diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2019-12-13 11:29:12 +0100 |
---|---|---|
committer | Dawid Dziurla <dawidd0811@gmail.com> | 2019-12-13 11:31:04 +0100 |
commit | be8f589c325e7a7d78c753a2571577eb76cba4ad (patch) | |
tree | 89bd2ab275e48bba66c35a1696f21e2a7f1612d8 /vendor/github.com | |
parent | 3074ae99ead364d38c0d271df18bdf95eacfa8ea (diff) |
update dependencies
Diffstat (limited to 'vendor/github.com')
73 files changed, 3288 insertions, 711 deletions
diff --git a/vendor/github.com/integrii/flaggy/.gitignore b/vendor/github.com/integrii/flaggy/.gitignore index a1338d685..f46854f39 100644 --- a/vendor/github.com/integrii/flaggy/.gitignore +++ b/vendor/github.com/integrii/flaggy/.gitignore @@ -12,3 +12,5 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +.idea/ diff --git a/vendor/github.com/integrii/flaggy/README.md b/vendor/github.com/integrii/flaggy/README.md index dffcf99cf..740811fc7 100644 --- a/vendor/github.com/integrii/flaggy/README.md +++ b/vendor/github.com/integrii/flaggy/README.md @@ -172,41 +172,57 @@ Other more specific types can also be used as flag types. They will be automati - time.Duration - []time.Duration -# Recommended Program Structure +# An Example Program -Best practice when using flaggy includes setting your program's name, description, and version (at build time). +Best practice when using flaggy includes setting your program's name, description, and version (at build time) as shown in this example program. ```go package main import "github.com/integrii/flaggy" -// make a variable for the version which will be set at build time +// Make a variable for the version which will be set at build time. var version = "unknown" -// keep subcommands as globals so you can easily check if they were used later on +// Keep subcommands as globals so you can easily check if they were used later on. var mySubcommand *flaggy.Subcommand +// Setup the variables you want your incoming flags to set. +var testVar string + +// If you would like an environment variable as the default for a value, just populate the flag +// with the value of the environment by default. If the flag corresponding to this value is not +// used, then it will not be changed. +var myVar = os.Getenv("MY_VAR") + + func init() { // Set your program's name and description. These appear in help output. flaggy.SetName("Test Program") flaggy.SetDescription("A little example program") - // you can disable various things by changing bools on the default parser - // (or your own parser if you have created one) + // You can disable various things by changing bools on the default parser + // (or your own parser if you have created one). flaggy.DefaultParser.ShowHelpOnUnexpected = false - // you can set a help prepend or append on the default parser + // You can set a help prepend or append on the default parser. flaggy.DefaultParser.AdditionalHelpPrepend = "http://github.com/integrii/flaggy" + + // Add a flag to the main program (this will be available in all subcommands as well). + flaggy.String(&testVar, "tv", "testVariable", "A variable just for testing things!") - // create any subcommands and set their parameters + // Create any subcommands and set their parameters. mySubcommand = flaggy.NewSubcommand("mySubcommand") mySubcommand.Description = "My great subcommand!" + + // Add a flag to the subcommand. + mySubcommand.String(&myVar, "mv", "myVariable", "A variable just for me!") - // set the version and parse all inputs into variables + // Set the version and parse all inputs into variables. flaggy.SetVersion(version) flaggy.Parse() } + func main(){ if mySubcommand.Used { ... diff --git a/vendor/github.com/integrii/flaggy/argumentParser.go b/vendor/github.com/integrii/flaggy/argumentParser.go index 089f2c5ce..34d00f960 100644 --- a/vendor/github.com/integrii/flaggy/argumentParser.go +++ b/vendor/github.com/integrii/flaggy/argumentParser.go @@ -5,22 +5,20 @@ package flaggy // The return values represent the key being set, and any errors // returned when setting the key, such as failures to convert the string // into the appropriate flag value. We stop assigning values as soon -// as we find a parser that accepts it. +// as we find a any parser that accepts it. func setValueForParsers(key string, value string, parsers ...ArgumentParser) (bool, error) { - var valueWasSet bool - for _, p := range parsers { valueWasSet, err := p.SetValueForKey(key, value) if err != nil { return valueWasSet, err } if valueWasSet { - break + return true, nil } } - return valueWasSet, nil + return false, nil } // ArgumentParser represents a parser or subcommand diff --git a/vendor/github.com/integrii/flaggy/main.go b/vendor/github.com/integrii/flaggy/main.go index b44cd9155..b242cb61d 100644 --- a/vendor/github.com/integrii/flaggy/main.go +++ b/vendor/github.com/integrii/flaggy/main.go @@ -327,6 +327,18 @@ func exitOrPanic(code int) { os.Exit(code) } +// ShowHelpOnUnexpectedEnable enables the ShowHelpOnUnexpected behavior on the +// default parser. This causes unknown inputs to error out. +func ShowHelpOnUnexpectedEnable() { + DefaultParser.ShowHelpOnUnexpected = true +} + +// ShowHelpOnUnexpectedDisable disables the ShowHelpOnUnexpected behavior on the +// default parser. This causes unknown inputs to error out. +func ShowHelpOnUnexpectedDisable() { + DefaultParser.ShowHelpOnUnexpected = false +} + // AddPositionalValue adds a positional value to the main parser at the global // context func AddPositionalValue(assignmentVar *string, name string, relativePosition int, required bool, description string) { diff --git a/vendor/github.com/integrii/flaggy/parsedValue.go b/vendor/github.com/integrii/flaggy/parsedValue.go new file mode 100644 index 000000000..04ada324a --- /dev/null +++ b/vendor/github.com/integrii/flaggy/parsedValue.go @@ -0,0 +1,23 @@ +package flaggy + +// parsedValue represents a flag or subcommand that was parsed. Primairily used +// to account for all parsed values in order to determine if unknown values were +// passed to the root parser after all subcommands have been parsed. +type parsedValue struct { + Key string + Value string + IsPositional bool // indicates that this value was positional and not a key/value +} + +// newParsedValue creates and returns a new parsedValue struct with the +// supplied values set +func newParsedValue(key string, value string, isPositional bool) parsedValue { + if len(key) == 0 && len(value) == 0 { + panic("cant add parsed value with no key or value") + } + return parsedValue{ + Key: key, + Value: value, + IsPositional: isPositional, + } +} diff --git a/vendor/github.com/integrii/flaggy/parser.go b/vendor/github.com/integrii/flaggy/parser.go index 066393266..41ab76e60 100644 --- a/vendor/github.com/integrii/flaggy/parser.go +++ b/vendor/github.com/integrii/flaggy/parser.go @@ -4,18 +4,20 @@ import ( "errors" "fmt" "os" + "strconv" "text/template" ) -// Parser represents the set of vars and subcommands we are expecting -// from our input args, and the parser than handles them all. +// Parser represents the set of flags and subcommands we are expecting +// from our input arguments. Parser is the top level struct responsible for +// parsing an entire set of subcommands and flags. type Parser struct { Subcommand Version string // the optional version of the parser. ShowHelpWithHFlag bool // display help when -h or --help passed ShowVersionWithVersionFlag bool // display the version when --version passed - ShowHelpOnUnexpected bool // display help when an unexpected flag is passed + ShowHelpOnUnexpected bool // display help when an unexpected flag or subcommand is passed TrailingArguments []string // everything after a -- is placed here HelpTemplate *template.Template // template for Help output trailingArgumentsExtracted bool // indicates that trailing args have been parsed and should not be appended again @@ -46,8 +48,89 @@ func (p *Parser) ParseArgs(args []string) error { return errors.New("Parser.Parse() called twice on parser with name: " + " " + p.Name + " " + p.ShortName) } p.parsed = true - // debugPrint("Kicking off parsing with args:", args) - return p.parse(p, args, 0) + + debugPrint("Kicking off parsing with args:", args) + err := p.parse(p, args, 0) + if err != nil { + return err + } + + // if we are set to crash on unexpected args, look for those here TODO + if p.ShowHelpOnUnexpected { + parsedValues := p.findAllParsedValues() + debugPrint("parsedValues:", parsedValues) + argsNotParsed := findArgsNotInParsedValues(args, parsedValues) + if len(argsNotParsed) > 0 { + // flatten out unused args for our error message + var argsNotParsedFlat string + for _, a := range argsNotParsed { + argsNotParsedFlat = argsNotParsedFlat + " " + a + } + p.ShowHelpAndExit("Unknown arguments supplied: " + argsNotParsedFlat) + } + } + + return nil +} + +// findArgsNotInParsedValues finds arguments not used in parsed values. The +// incoming args should be in the order supplied by the user and should not +// include the invoked binary, which is normally the first thing in os.Args. +func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []string { + var argsNotUsed []string + var skipNext bool + for _, a := range args { + + // if the final argument (--) is seen, then we stop checking because all + // further values are trailing arguments. + if determineArgType(a) == argIsFinal { + return argsNotUsed + } + + // allow for skipping the next arg when needed + if skipNext { + skipNext = false + continue + } + + // strip flag slashes from incoming arguments so they match up with the + // keys from parsedValues. + arg := parseFlagToName(a) + + // indicates that we found this arg used in one of the parsed values. Used + // to indicate which values should be added to argsNotUsed. + var foundArgUsed bool + + // search all args for a corresponding parsed value + for _, pv := range parsedValues { + // this argumenet was a key + // debugPrint(pv.Key, "==", arg) + debugPrint(pv.Key + "==" + arg + " || (" + strconv.FormatBool(pv.IsPositional) + " && " + pv.Value + " == " + arg + ")") + if pv.Key == arg || (pv.IsPositional && pv.Value == arg) { + debugPrint("Found matching parsed arg for " + pv.Key) + foundArgUsed = true // the arg was used in this parsedValues set + // if the value is not a positional value and the parsed value had a + // value that was not blank, we skip the next value in the argument list + if !pv.IsPositional && len(pv.Value) > 0 { + skipNext = true + break + } + } + // this prevents excessive parsed values from being checked after we find + // the arg used for the first time + if foundArgUsed { + break + } + } + + // if the arg was not used in any parsed values, then we add it to the slice + // of arguments not used + if !foundArgUsed { + argsNotUsed = append(argsNotUsed, arg) + } + } + + return argsNotUsed } // ShowVersionAndExit shows the version of this parser @@ -105,7 +188,8 @@ func (p *Parser) ShowHelpWithMessage(message string) { } } -// Disable show version with --version. It is enabled by default. +// DisableShowVersionWithVersion disables the showing of version information +// with --version. It is enabled by default. func (p *Parser) DisableShowVersionWithVersion() { p.ShowVersionWithVersionFlag = false } diff --git a/vendor/github.com/integrii/flaggy/subCommand.go b/vendor/github.com/integrii/flaggy/subCommand.go index c0c13073d..7f99e3e8a 100644 --- a/vendor/github.com/integrii/flaggy/subCommand.go +++ b/vendor/github.com/integrii/flaggy/subCommand.go @@ -23,15 +23,20 @@ type Subcommand struct { Subcommands []*Subcommand Flags []*Flag PositionalFlags []*PositionalValue - AdditionalHelpPrepend string // additional prepended message when Help is displayed - AdditionalHelpAppend string // additional appended message when Help i |