From e3bb76244b95b7faaa924254c5cc880b5d7c3ef6 Mon Sep 17 00:00:00 2001 From: Jocelyn Giroux Date: Mon, 30 Sep 2024 08:34:14 -0400 Subject: [PATCH] Merge with upstream - Remove compilation error - No longer consider single - as an error (that could be an argument) --- alias.go | 2 - app_test.go | 4 +- cmd.go | 10 ---- doc.go | 108 ++++++++++++++++++++++---------------------- examples_test.go | 2 +- guesswidth.go | 1 + guesswidth_unix.go | 1 + values.go | 7 +-- values_generated.go | 7 +-- 9 files changed, 65 insertions(+), 77 deletions(-) diff --git a/alias.go b/alias.go index c193654..f1e8894 100644 --- a/alias.go +++ b/alias.go @@ -58,8 +58,6 @@ func (f *FlagClause) addAlias(alias string, kind aliasKind) error { return nil } -type aliasGroupMixin struct{} - // This function find the corresponding flag either by name or though aliases. // If the resulted flag correspond to a negative alias (-no-boolOption), invert is set to true func (fg *flagGroup) getFlagAlias(name string) (flag *FlagClause, invert bool, err error) { diff --git a/app_test.go b/app_test.go index df562f6..df31719 100644 --- a/app_test.go +++ b/app_test.go @@ -520,7 +520,7 @@ func TestDefaultValues(t *testing.T) { if c.reset { a.ResetInitOnlyOnce() } - _, err = a.Parse(split(c.args2)) + a.Parse(split(c.args2)) } assert.Equal(t, c.expectB, a.b, "bool(s)") assert.Equal(t, c.expectS, a.s, "string(s)") @@ -646,7 +646,7 @@ func TestUnmanaged(t *testing.T) { {"Incomplete switch", true, "-", []bool{false, false, false, false, false}, []string{"", "", "", "", ""}, - nil, fmt.Errorf("unknown short flag '-'")}, + []string{"-"}, nil}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { diff --git a/cmd.go b/cmd.go index 799582a..87ed4eb 100644 --- a/cmd.go +++ b/cmd.go @@ -166,16 +166,6 @@ func newCmdGroup(app *Application) *cmdGroup { } } -func (c *cmdGroup) flattenedCommands() (out []*CmdClause) { - for _, cmd := range c.commandOrder { - if len(cmd.commands) == 0 { - out = append(out, cmd) - } - out = append(out, cmd.flattenedCommands()...) - } - return -} - func (c *cmdGroup) addCommand(name, help string) *CmdClause { cmd := newCommand(c.app, name, help) c.commands[name] = cmd diff --git a/doc.go b/doc.go index 8a72729..a8ca25d 100644 --- a/doc.go +++ b/doc.go @@ -1,68 +1,68 @@ // Package kingpin provides command line interfaces like this: // -// $ chat -// usage: chat [] [] [ ...] +// $ chat +// usage: chat [] [] [ ...] // -// Flags: -// --debug enable debug mode -// --help Show help. -// --server=127.0.0.1 server address +// Flags: +// --debug enable debug mode +// --help Show help. +// --server=127.0.0.1 server address // -// Commands: -// help -// Show help for a command. +// Commands: +// help +// Show help for a command. // -// post [] -// Post a message to a channel. +// post [] +// Post a message to a channel. // -// register -// Register a new user. +// register +// Register a new user. // -// $ chat help post -// usage: chat [] post [] [] +// $ chat help post +// usage: chat [] post [] [] // -// Post a message to a channel. +// Post a message to a channel. // -// Flags: -// --image=IMAGE image to post +// Flags: +// --image=IMAGE image to post // -// Args: -// channel to post to -// [] text to post -// $ chat post --image=~/Downloads/owls.jpg pics +// Args: +// channel to post to +// [] text to post +// $ chat post --image=~/Downloads/owls.jpg pics // // From code like this: // -// package main -// -// import "github.com/alecthomas/kingpin/v2" -// -// var ( -// debug = kingpin.Flag("debug", "enable debug mode").Default("false").Bool() -// serverIP = kingpin.Flag("server", "server address").Default("127.0.0.1").IP() -// -// register = kingpin.Command("register", "Register a new user.") -// registerNick = register.Arg("nick", "nickname for user").Required().String() -// registerName = register.Arg("name", "name of user").Required().String() -// -// post = kingpin.Command("post", "Post a message to a channel.") -// postImage = post.Flag("image", "image to post").ExistingFile() -// postChannel = post.Arg("channel", "channel to post to").Required().String() -// postText = post.Arg("text", "text to post").String() -// ) -// -// func main() { -// switch kingpin.Parse() { -// // Register user -// case "register": -// println(*registerNick) -// -// // Post message -// case "post": -// if *postImage != nil { -// } -// if *postText != "" { -// } -// } -// } +// package main +// +// import "github.com/alecthomas/kingpin/v2" +// +// var ( +// debug = kingpin.Flag("debug", "enable debug mode").Default("false").Bool() +// serverIP = kingpin.Flag("server", "server address").Default("127.0.0.1").IP() +// +// register = kingpin.Command("register", "Register a new user.") +// registerNick = register.Arg("nick", "nickname for user").Required().String() +// registerName = register.Arg("name", "name of user").Required().String() +// +// post = kingpin.Command("post", "Post a message to a channel.") +// postImage = post.Flag("image", "image to post").ExistingFile() +// postChannel = post.Arg("channel", "channel to post to").Required().String() +// postText = post.Arg("text", "text to post").String() +// ) +// +// func main() { +// switch kingpin.Parse() { +// // Register user +// case "register": +// println(*registerNick) +// +// // Post message +// case "post": +// if *postImage != nil { +// } +// if *postText != "" { +// } +// } +// } package kingpin diff --git a/examples_test.go b/examples_test.go index 7c3e34f..9705596 100644 --- a/examples_test.go +++ b/examples_test.go @@ -31,7 +31,7 @@ func HTTPHeader(s Settings) (target *http.Header) { return } -// This example ilustrates how to define custom parsers. HTTPHeader +// This example illustrates how to define custom parsers. HTTPHeader // cumulatively parses each encountered --header flag into a http.Header struct. func ExampleValue() { var ( diff --git a/guesswidth.go b/guesswidth.go index a269531..da3ba09 100644 --- a/guesswidth.go +++ b/guesswidth.go @@ -1,3 +1,4 @@ +//go:build appengine || (!linux && !freebsd && !darwin && !dragonfly && !netbsd && !openbsd) // +build appengine !linux,!freebsd,!darwin,!dragonfly,!netbsd,!openbsd package kingpin diff --git a/guesswidth_unix.go b/guesswidth_unix.go index ad8163f..3429240 100644 --- a/guesswidth_unix.go +++ b/guesswidth_unix.go @@ -1,3 +1,4 @@ +//go:build (!appengine && linux) || freebsd || darwin || dragonfly || netbsd || openbsd // +build !appengine,linux freebsd darwin dragonfly netbsd openbsd package kingpin diff --git a/values.go b/values.go index 1b61e93..cf5ec0b 100644 --- a/values.go +++ b/values.go @@ -87,9 +87,10 @@ type accumulator struct { // Use reflection to accumulate values into a slice. // // target := []string{} -// newAccumulator(&target, func (value interface{}) Value { -// return newStringValue(value.(*string)) -// }) +// +// newAccumulator(&target, func (value interface{}) Value { +// return newStringValue(value.(*string)) +// }) func newAccumulator(slice interface{}, element func(value interface{}) Value) *accumulator { typ := reflect.TypeOf(slice) if typ.Kind() != reflect.Ptr || typ.Elem().Kind() != reflect.Slice { diff --git a/values_generated.go b/values_generated.go index 8d492bf..1d12bd4 100644 --- a/values_generated.go +++ b/values_generated.go @@ -62,11 +62,8 @@ func newStringValue(p *string) *stringValue { } func (f *stringValue) Set(s string) error { - v, err := s, error(nil) - if err == nil { - *f.v = (string)(v) - } - return err + *f.v = (string)(s) + return nil } func (f *stringValue) Get() interface{} { return (string)(*f.v) }