Skip to content
Permalink
Browse files

add is set method to flag interface - refer #294

  • Loading branch information
asahasrabuddhe committed Sep 15, 2019
1 parent 2746d8d commit ef1ba861f79e79c12b58afc4e5c870fe28d44452
Showing with 197 additions and 800 deletions.
  1. +1 −0 CHANGELOG.md
  2. +1 −26 app.go
  3. +4 −0 app_test.go
  4. +1 −7 args.go
  5. +0 −7 category.go
  6. +0 −479 cli-v1-to-v2
  7. +18 −17 context.go
  8. +19 −84 context_test.go
  9. +6 −37 flag.go
  10. +9 −10 flag_bool.go
  11. +10 −9 flag_duration.go
  12. +9 −9 flag_float64.go
  13. +14 −13 flag_float64_slice.go
  14. +16 −12 flag_generic.go
  15. +9 −9 flag_int.go
  16. +9 −9 flag_int64.go
  17. +8 −9 flag_int64_slice.go
  18. +8 −9 flag_int_slice.go
  19. +7 −0 flag_path.go
  20. +25 −27 flag_string.go
  21. +9 −9 flag_string_slice.go
  22. +7 −9 flag_uint.go
  23. +7 −9 flag_uint64.go
@@ -13,6 +13,7 @@
### Changed
- `Context.FlagNames` now returns all flags in the context lineage
- `Context.IsSet` now considers the full context lineage
- Added `IsSet` method to the `Flag` interface which allows us to detect whether or not a flag has been set

### Removed
- the ability to specify `&StringSlice{...string}` or `&IntSlice{...int}`.
27 app.go
@@ -14,8 +14,6 @@ import (
var (
changeLogURL = "https://github.com/urfave/cli/blob/master/CHANGELOG.md"
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
// unused variable. commented for now. will remove in future if agreed upon by everyone
//runAndExitOnErrorDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-runandexitonerror", changeLogURL)

contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."

@@ -89,7 +87,7 @@ type App struct {
// render custom help text by setting this variable.
CustomAppHelpTemplate string
// Boolean to enable short-option handling so user can combine several
// single-character bool arguements into one
// single-character bool arguments into one
// i.e. foobar -o -v -> foobar -ov
UseShortOptionHandling bool

@@ -182,11 +180,6 @@ func (a *App) Setup() {
}
}

//if a.EnableShellCompletion {
// a.appendFlag(GenerateCompletionFlag)
// a.appendFlag(InitCompletionFlag)
//}

if !a.HideVersion {
a.appendFlag(VersionFlag)
}
@@ -246,14 +239,6 @@ func (a *App) Run(arguments []string) (err error) {
return nil
}

//if done, cerr := checkInitCompletion(context); done {
// if cerr != nil {
// err = cerr
// } else {
// return nil
// }
//}

if err != nil {
if a.OnUsageError != nil {
err := a.OnUsageError(context, err, false)
@@ -361,17 +346,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
}
a.Commands = newCmds

//<<<<<<< HEAD
// // append flags
// if a.EnableShellCompletion {
// a.appendFlag(GenerateCompletionFlag)
// }
//
// // parse flags
// set, err := flagSet(a.Name, a.Flags)
//=======
_, err = a.newFlagSet()
//>>>>>>> master
if err != nil {
return err
}
@@ -1993,6 +1993,10 @@ func (c *customBoolFlag) Apply(set *flag.FlagSet) error {
return nil
}

func (c *customBoolFlag) IsSet() bool {
return false
}

func TestCustomFlagsUnused(t *testing.T) {
app := &App{
Flags: []Flag{&customBoolFlag{"custom"}},
@@ -1,11 +1,5 @@
package cli

import "errors"

var (
argsRangeErr = errors.New("index out of range")
)

type Args interface {
// Get returns the nth argument, or else a blank string
Get(n int) string
@@ -55,6 +49,6 @@ func (a *args) Present() bool {

func (a *args) Slice() []string {
ret := make([]string, len(*a))
copy(ret, []string(*a))
copy(ret, *a)
return ret
}
@@ -59,13 +59,6 @@ type commandCategory struct {
commands []*Command
}

func newCommandCategory(name string) *commandCategory {
return &commandCategory{
name: name,
commands: []*Command{},
}
}

func (c *commandCategory) Name() string {
return c.name
}

0 comments on commit ef1ba86

Please sign in to comment.
You can’t perform that action at this time.