Skip to content

Commit

Permalink
add is set method to flag interface - refer #294
Browse files Browse the repository at this point in the history
  • Loading branch information
asahasrabuddhe committed Sep 15, 2019
1 parent 2746d8d commit ef1ba86
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 800 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`.
Expand Down
27 changes: 1 addition & 26 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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

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

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

if !a.HideVersion {
a.appendFlag(VersionFlag)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
8 changes: 1 addition & 7 deletions args.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
7 changes: 0 additions & 7 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit ef1ba86

Please sign in to comment.