From fa8580522211fddd465dffee6003cd07972a7260 Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Sun, 6 Jan 2019 13:59:51 +0000 Subject: [PATCH] fix opt cleared with defualt --- Gopkg.lock | 6 +++--- Gopkg.toml | 2 +- vendor/github.com/jessevdk/go-flags/parser.go | 20 +++++++++++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 05584d34..09eb1592 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -14,10 +14,10 @@ revision = "d32a9ef172a1ec91efdf3ce26b240c946285bfe7" [[projects]] - branch = "ignore_unknown_ini" + branch = "hack_global_ref" name = "github.com/jessevdk/go-flags" packages = ["."] - revision = "f0dfbc82957e3db331cb27732d270e275614b005" + revision = "3e2b0d3b82050426db6ebde363a66b2c7711d8fc" source = "https://github.com/tg123/go-flags" [[projects]] @@ -66,6 +66,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "534da9de5467ab2fd3960701473a3fd7da82684491b7b65f21644b0a6b7147f5" + inputs-digest = "9e42cf42e27d0d44f175e90958f545127d53a6ba490856c10094dffdb54e79f1" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 1301cb30..ea505b41 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -30,6 +30,6 @@ name = "github.com/jinzhu/gorm" [[constraint]] - branch = "ignore_unknown_ini" + branch = "hack_global_ref" name = "github.com/jessevdk/go-flags" source = "https://github.com/tg123/go-flags" diff --git a/vendor/github.com/jessevdk/go-flags/parser.go b/vendor/github.com/jessevdk/go-flags/parser.go index 0a7922a0..d22056e5 100644 --- a/vendor/github.com/jessevdk/go-flags/parser.go +++ b/vendor/github.com/jessevdk/go-flags/parser.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "path" + "reflect" "sort" "strings" "unicode/utf8" @@ -123,6 +124,8 @@ type parseState struct { command *Command lookup lookup + + setcalled map[reflect.Value]bool } // Parse is a convenience function to parse command line options with default @@ -230,8 +233,9 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) { } s := &parseState{ - args: args, - retargs: make([]string, 0, len(args)), + args: args, + retargs: make([]string, 0, len(args)), + setcalled: make(map[reflect.Value]bool), } p.fillParseState(s) @@ -292,11 +296,16 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) { } if s.err == nil { + p.eachOption(func(c *Command, g *Group, option *Option) { if option.preventDefault { return } + if _, ok := s.setcalled[option.value]; ok { + return + } + option.clearDefault() }) @@ -501,6 +510,13 @@ func (p *parseState) estimateCommand() error { } func (p *Parser) parseOption(s *parseState, name string, option *Option, canarg bool, argument *string) (err error) { + + defer func() { + if err == nil { + s.setcalled[option.value] = true + } + }() + if !option.canArgument() { if argument != nil { return newErrorf(ErrNoArgumentForBool, "bool flag `%s' cannot have an argument", option)