Skip to content

Commit

Permalink
Merge branch 'master' into v2-master-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
asahasrabuddhe committed Sep 16, 2019
2 parents b161244 + c71fbce commit a9d5b68
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 54 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -711,6 +707,7 @@ package main

import (
"fmt"
"log"
"os"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -768,19 +766,24 @@ func main() {
},
}

=======
>>>>>>> master
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
```

<<<<<<< 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):
Expand Down Expand Up @@ -882,6 +885,7 @@ import (
)

func main() {
<<<<<<< HEAD
app := &cli.App{
Commands: []*cli.Command{
{
Expand All @@ -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
},
}

Expand Down Expand Up @@ -1570,7 +1589,7 @@ func main() {
app.Writer = &hexWriter{}
app.ErrWriter = &hexWriter{}
}

app.Run(os.Args)
}

Expand Down
2 changes: 2 additions & 0 deletions altsrc/flag_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions altsrc/json_source_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
5 changes: 0 additions & 5 deletions altsrc/toml_command_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
5 changes: 0 additions & 5 deletions altsrc/toml_file_loader.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
5 changes: 0 additions & 5 deletions altsrc/yaml_command_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
5 changes: 0 additions & 5 deletions altsrc/yaml_file_loader.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
33 changes: 25 additions & 8 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func (c *Context) FlagNames() []string {
var names []string
for _, ctx := range c.Lineage() {
ctx.flagSet.Visit(makeFlagNameVisitor(&names))

}
return names
}
Expand Down
3 changes: 2 additions & 1 deletion docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion flag_int64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (i *Int64Slice) Set(value string) error {
}

i.slice = append(i.slice, tmp)

return nil
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (s *StringSlice) Set(value string) error {
}

s.slice = append(s.slice, value)

return nil
}

Expand Down Expand Up @@ -132,6 +133,7 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
}
set.Var(f.Value, name, f.Usage)
}

return nil
}

Expand Down
15 changes: 0 additions & 15 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit a9d5b68

Please sign in to comment.