diff --git a/README.md b/README.md index c701b36..2a928a6 100644 --- a/README.md +++ b/README.md @@ -104,11 +104,7 @@ import ( ... ``` -### Pinning to the `v1` releases - -Similarly to the section above describing use of the `v2` branch, if one wants -to avoid any unexpected compatibility pains once `v2` becomes `master`, then -pinning to `v1` is an acceptable option, e.g.: +### Using `v1` releases ``` $ go get github.com/urfave/cli @@ -711,6 +707,7 @@ package main import ( "fmt" + "log" "os" "github.com/urfave/cli/v2" @@ -738,6 +735,7 @@ func main() { #### Default Values for help output +<<<<<<< HEAD Sometimes it's useful to specify a flag's default help-text value within the flag declaration. This can be useful if the default value for a flag is a computed value. The default value can be set via the `DefaultText` struct field. For example this: @@ -768,6 +766,8 @@ func main() { }, } +======= +>>>>>>> master err := app.Run(os.Args) if err != nil { log.Fatal(err) @@ -775,12 +775,15 @@ func main() { } ``` +<<<<<<< HEAD Will result in help output like: ``` --port value Use a randomized port (default: random) ``` +======= +>>>>>>> master #### Precedence The precedence for flag value sources is as follows (highest to lowest): @@ -882,6 +885,7 @@ import ( ) func main() { +<<<<<<< HEAD app := &cli.App{ Commands: []*cli.Command{ { @@ -895,6 +899,21 @@ func main() { Name: "remove", Category: "template", }, +======= + app := cli.NewApp() + + app.Commands = []cli.Command{ + { + Name: "noop", + }, + { + Name: "add", + Category: "Template actions", + }, + { + Name: "remove", + Category: "Template actions", +>>>>>>> master }, } @@ -1570,7 +1589,7 @@ func main() { app.Writer = &hexWriter{} app.ErrWriter = &hexWriter{} } - + app.Run(os.Args) } diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index de3e2b5..29572a6 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -1,3 +1,5 @@ +// Code generated by fg; DO NOT EDIT. + package altsrc import ( diff --git a/altsrc/json_source_context.go b/altsrc/json_source_context.go index 6f66aa3..31c46cd 100644 --- a/altsrc/json_source_context.go +++ b/altsrc/json_source_context.go @@ -203,6 +203,5 @@ func jsonGetValue(key string, m map[string]interface{}) (interface{}, error) { type jsonSource struct { file string - deserialized map[string]interface { - } + deserialized map[string]interface{} } diff --git a/altsrc/toml_command_test.go b/altsrc/toml_command_test.go index 9c96dce..0ae06cf 100644 --- a/altsrc/toml_command_test.go +++ b/altsrc/toml_command_test.go @@ -1,8 +1,3 @@ -// Disabling building of toml support in cases where golang is 1.0 or 1.1 -// as the encoding library is not implemented or supported. - -// +build go1.2 - package altsrc import ( diff --git a/altsrc/toml_file_loader.go b/altsrc/toml_file_loader.go index 3f410fc..c679fdb 100644 --- a/altsrc/toml_file_loader.go +++ b/altsrc/toml_file_loader.go @@ -1,8 +1,3 @@ -// Disabling building of toml support in cases where golang is 1.0 or 1.1 -// as the encoding library is not implemented or supported. - -// +build go1.2 - package altsrc import ( diff --git a/altsrc/yaml_command_test.go b/altsrc/yaml_command_test.go index 8659951..4303e9a 100644 --- a/altsrc/yaml_command_test.go +++ b/altsrc/yaml_command_test.go @@ -1,8 +1,3 @@ -// Disabling building of yaml support in cases where golang is 1.0 or 1.1 -// as the encoding library is not implemented or supported. - -// +build go1.2 - package altsrc import ( diff --git a/altsrc/yaml_file_loader.go b/altsrc/yaml_file_loader.go index 9b1dc05..cf2f8a5 100644 --- a/altsrc/yaml_file_loader.go +++ b/altsrc/yaml_file_loader.go @@ -1,8 +1,3 @@ -// Disabling building of yaml support in cases where golang is 1.0 or 1.1 -// as the encoding library is not implemented or supported. - -// +build go1.2 - package altsrc import ( diff --git a/app.go b/app.go index 767b1f1..3300cc5 100644 --- a/app.go +++ b/app.go @@ -11,14 +11,14 @@ import ( "time" ) -//var ( -// changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" -// appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) -// contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." -// errInvalidActionType = NewExitError("ERROR invalid Action type. "+ -// fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ -// fmt.Sprintf("See %s", appActionDeprecationURL), 2) -//) +var ( + changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" + appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) + contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you." + errInvalidActionType = NewExitError("ERROR invalid Action type. "+ + fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ + fmt.Sprintf("See %s", appActionDeprecationURL), 2) +) // App is the main structure of a cli application. It is recommended that // an app be created with the cli.NewApp() function @@ -532,3 +532,20 @@ func (a *Author) String() string { return fmt.Sprintf("%v%v", a.Name, e) } + +// HandleAction attempts to figure out which Action signature was used. If +// it's an ActionFunc or a func with the legacy signature for Action, the func +// is run! +func HandleAction(action interface{}, context *Context) (err error) { + switch a := action.(type) { + case ActionFunc: + return a(context) + case func(*Context) error: + return a(context) + case func(*Context): // deprecated function signature + a(context) + return nil + } + + return errInvalidActionType +} diff --git a/appveyor.yml b/appveyor.yml index 1f30f3b..3447d40 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,15 +12,23 @@ cache: environment: GOPATH: C:\gopath GOVERSION: 1.11.x +<<<<<<< HEAD GO111MODULE: on GOPROXY: https://proxy.golang.org +======= +>>>>>>> master install: - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% - go version - go env +<<<<<<< HEAD - go get github.com/urfave/gfmrun/cmd/gfmrun - go mod vendor +======= + - go get github.com/urfave/gfmrun/... + - go get -v -t ./... +>>>>>>> master build_script: - go run build.go vet diff --git a/context.go b/context.go index 70af324..535c388 100644 --- a/context.go +++ b/context.go @@ -98,7 +98,6 @@ func (c *Context) FlagNames() []string { var names []string for _, ctx := range c.Lineage() { ctx.flagSet.Visit(makeFlagNameVisitor(&names)) - } return names } diff --git a/docs.go b/docs.go index 2e8b974..a8f5de9 100644 --- a/docs.go +++ b/docs.go @@ -102,13 +102,14 @@ func prepareFlags( sep, opener, closer, value string, addDetails bool, ) []string { - var args []string + args := []string{} for _, f := range flags { flag, ok := f.(DocGenerationFlag) if !ok { continue } modifiedArg := opener + for _, s := range flag.Names() { trimmed := strings.TrimSpace(s) if len(modifiedArg) > len(opener) { diff --git a/flag_int64_slice.go b/flag_int64_slice.go index 818f858..5aa5e2a 100644 --- a/flag_int64_slice.go +++ b/flag_int64_slice.go @@ -39,6 +39,7 @@ func (i *Int64Slice) Set(value string) error { } i.slice = append(i.slice, tmp) + return nil } @@ -144,7 +145,13 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error { // Int64Slice looks up the value of a local Int64SliceFlag, returns // nil if not found func (c *Context) Int64Slice(name string) []int64 { - if fs := lookupFlagSet(name, c); fs != nil { + return lookupInt64Slice(name, c.flagSet) +} + +// GlobalInt64Slice looks up the value of a global Int64SliceFlag, returns +// nil if not found +func (c *Context) GlobalInt64Slice(name string) []int64 { + if fs := lookupGlobalFlagSet(name, c); fs != nil { return lookupInt64Slice(name, fs) } return nil diff --git a/flag_string_slice.go b/flag_string_slice.go index 0835833..a114a49 100644 --- a/flag_string_slice.go +++ b/flag_string_slice.go @@ -33,6 +33,7 @@ func (s *StringSlice) Set(value string) error { } s.slice = append(s.slice, value) + return nil } @@ -132,6 +133,7 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error { } set.Var(f.Value, name, f.Usage) } + return nil } diff --git a/flag_test.go b/flag_test.go index b4b2739..5d0ecae 100644 --- a/flag_test.go +++ b/flag_test.go @@ -229,21 +229,6 @@ var prefixStringFlagTests = []struct { }, expected: "name: config,c, ph: CONFIG\tLoad configuration from CONFIG (default: \"config.json\")"}, } -//func TestFlagNamePrefixer(t *testing.T) { -// defer func() { -// FlagNamePrefixer = prefixedNames -// }() -// -// for _, test := range prefixStringFlagTests { -// FlagNamePrefixer = test.prefixer -// fl := StringFlag{Name: test.name, Aliases: test.aliases, Usage: test.usage, Value: test.value} -// output := fl.String() -// if output != test.expected { -// t.Errorf("%q does not match %q", output, test.expected) -// } -// } -//} - func TestStringFlagApply_SetsAllNames(t *testing.T) { v := "mmm" fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v}