Merge branch 'master' into v2-master-merge

main
Ajitem Sahasrabuddhe 5 years ago
commit a9d5b68df5
No known key found for this signature in database
GPG Key ID: 5B0EE10DAA76876C

@ -104,11 +104,7 @@ import (
... ...
``` ```
### Pinning to the `v1` releases ### Using `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.:
``` ```
$ go get github.com/urfave/cli $ go get github.com/urfave/cli
@ -711,6 +707,7 @@ package main
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -738,6 +735,7 @@ func main() {
#### Default Values for help output #### 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. 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: For example this:
@ -768,6 +766,8 @@ func main() {
}, },
} }
=======
>>>>>>> master
err := app.Run(os.Args) err := app.Run(os.Args)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -775,12 +775,15 @@ func main() {
} }
``` ```
<<<<<<< HEAD
Will result in help output like: Will result in help output like:
``` ```
--port value Use a randomized port (default: random) --port value Use a randomized port (default: random)
``` ```
=======
>>>>>>> master
#### Precedence #### Precedence
The precedence for flag value sources is as follows (highest to lowest): The precedence for flag value sources is as follows (highest to lowest):
@ -882,6 +885,7 @@ import (
) )
func main() { func main() {
<<<<<<< HEAD
app := &cli.App{ app := &cli.App{
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
@ -895,6 +899,21 @@ func main() {
Name: "remove", Name: "remove",
Category: "template", 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.Writer = &hexWriter{}
app.ErrWriter = &hexWriter{} app.ErrWriter = &hexWriter{}
} }
app.Run(os.Args) app.Run(os.Args)
} }

@ -1,3 +1,5 @@
// Code generated by fg; DO NOT EDIT.
package altsrc package altsrc
import ( import (

@ -203,6 +203,5 @@ func jsonGetValue(key string, m map[string]interface{}) (interface{}, error) {
type jsonSource struct { type jsonSource struct {
file string file string
deserialized map[string]interface { deserialized map[string]interface{}
}
} }

@ -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 package altsrc
import ( import (

@ -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 package altsrc
import ( import (

@ -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 package altsrc
import ( import (

@ -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 package altsrc
import ( import (

@ -11,14 +11,14 @@ import (
"time" "time"
) )
//var ( var (
// changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md" changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
// appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL) 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." 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. "+ errInvalidActionType = NewExitError("ERROR invalid Action type. "+
// fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+ fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+
// fmt.Sprintf("See %s", appActionDeprecationURL), 2) fmt.Sprintf("See %s", appActionDeprecationURL), 2)
//) )
// App is the main structure of a cli application. It is recommended that // App is the main structure of a cli application. It is recommended that
// an app be created with the cli.NewApp() function // 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) 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
}

@ -12,15 +12,23 @@ cache:
environment: environment:
GOPATH: C:\gopath GOPATH: C:\gopath
GOVERSION: 1.11.x GOVERSION: 1.11.x
<<<<<<< HEAD
GO111MODULE: on GO111MODULE: on
GOPROXY: https://proxy.golang.org GOPROXY: https://proxy.golang.org
=======
>>>>>>> master
install: install:
- set PATH=%GOPATH%\bin;C:\go\bin;%PATH% - set PATH=%GOPATH%\bin;C:\go\bin;%PATH%
- go version - go version
- go env - go env
<<<<<<< HEAD
- go get github.com/urfave/gfmrun/cmd/gfmrun - go get github.com/urfave/gfmrun/cmd/gfmrun
- go mod vendor - go mod vendor
=======
- go get github.com/urfave/gfmrun/...
- go get -v -t ./...
>>>>>>> master
build_script: build_script:
- go run build.go vet - go run build.go vet

@ -98,7 +98,6 @@ func (c *Context) FlagNames() []string {
var names []string var names []string
for _, ctx := range c.Lineage() { for _, ctx := range c.Lineage() {
ctx.flagSet.Visit(makeFlagNameVisitor(&names)) ctx.flagSet.Visit(makeFlagNameVisitor(&names))
} }
return names return names
} }

@ -102,13 +102,14 @@ func prepareFlags(
sep, opener, closer, value string, sep, opener, closer, value string,
addDetails bool, addDetails bool,
) []string { ) []string {
var args []string args := []string{}
for _, f := range flags { for _, f := range flags {
flag, ok := f.(DocGenerationFlag) flag, ok := f.(DocGenerationFlag)
if !ok { if !ok {
continue continue
} }
modifiedArg := opener modifiedArg := opener
for _, s := range flag.Names() { for _, s := range flag.Names() {
trimmed := strings.TrimSpace(s) trimmed := strings.TrimSpace(s)
if len(modifiedArg) > len(opener) { if len(modifiedArg) > len(opener) {

@ -39,6 +39,7 @@ func (i *Int64Slice) Set(value string) error {
} }
i.slice = append(i.slice, tmp) i.slice = append(i.slice, tmp)
return nil return nil
} }
@ -144,7 +145,13 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
// Int64Slice looks up the value of a local Int64SliceFlag, returns // Int64Slice looks up the value of a local Int64SliceFlag, returns
// nil if not found // nil if not found
func (c *Context) Int64Slice(name string) []int64 { 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 lookupInt64Slice(name, fs)
} }
return nil return nil

@ -33,6 +33,7 @@ func (s *StringSlice) Set(value string) error {
} }
s.slice = append(s.slice, value) s.slice = append(s.slice, value)
return nil return nil
} }
@ -132,6 +133,7 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
} }
set.Var(f.Value, name, f.Usage) set.Var(f.Value, name, f.Usage)
} }
return nil return nil
} }

@ -229,21 +229,6 @@ var prefixStringFlagTests = []struct {
}, expected: "name: config,c, ph: CONFIG\tLoad configuration from CONFIG (default: \"config.json\")"}, }, 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) { func TestStringFlagApply_SetsAllNames(t *testing.T) {
v := "mmm" v := "mmm"
fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v} fl := StringFlag{Name: "hay", Aliases: []string{"H", "hayyy"}, Destination: &v}

Loading…
Cancel
Save