Skip to content

Commit

Permalink
Merge with upstream
Browse files Browse the repository at this point in the history
- Remove compilation error
- No longer consider single - as an error (that could be an argument)
  • Loading branch information
jocgir committed Sep 30, 2024
1 parent 7c6aa06 commit e3bb762
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 77 deletions.
2 changes: 0 additions & 2 deletions alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
108 changes: 54 additions & 54 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
// Package kingpin provides command line interfaces like this:
//
// $ chat
// usage: chat [<flags>] <command> [<flags>] [<args> ...]
// $ chat
// usage: chat [<flags>] <command> [<flags>] [<args> ...]
//
// 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 <command>
// Show help for a command.
// Commands:
// help <command>
// Show help for a command.
//
// post [<flags>] <channel>
// Post a message to a channel.
// post [<flags>] <channel>
// Post a message to a channel.
//
// register <nick> <name>
// Register a new user.
// register <nick> <name>
// Register a new user.
//
// $ chat help post
// usage: chat [<flags>] post [<flags>] <channel> [<text>]
// $ chat help post
// usage: chat [<flags>] post [<flags>] <channel> [<text>]
//
// 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> channel to post to
// [<text>] text to post
// $ chat post --image=~/Downloads/owls.jpg pics
// Args:
// <channel> channel to post to
// [<text>] 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
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions guesswidth.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build appengine || (!linux && !freebsd && !darwin && !dragonfly && !netbsd && !openbsd)
// +build appengine !linux,!freebsd,!darwin,!dragonfly,!netbsd,!openbsd

package kingpin
Expand Down
1 change: 1 addition & 0 deletions guesswidth_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build (!appengine && linux) || freebsd || darwin || dragonfly || netbsd || openbsd
// +build !appengine,linux freebsd darwin dragonfly netbsd openbsd

package kingpin
Expand Down
7 changes: 4 additions & 3 deletions values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions values_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit e3bb762

Please sign in to comment.