Skip to content

Commit

Permalink
up: fix cmd init error, missing init cli parser
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 3, 2022
1 parent 3482598 commit 4c7ed4b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
go-version: ${{ matrix.go_version }}

- name: Revive check
uses: morphy2k/revive-action@v2.4.0
uses: morphy2k/revive-action@v2.4.1
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
# Exclude patterns, separated by semicolons (optional)
Expand Down
7 changes: 2 additions & 5 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,8 @@ func (c *Command) initialize() {
}
}

// init for cmd Arguments
c.Flags.SetName(cName)

// init for cmd flags
c.InitFlagSet(cName)
// init for cmd flags parser
c.InitParser(cName)

// format description
if len(c.Desc) > 0 {
Expand Down
4 changes: 0 additions & 4 deletions gflag/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func (ops *CliOpts) InitFlagSet(name string) {
return
}

// if ops.cfg == nil {
// ops.cfg = newDefaultFlagConfig()
// }

ops.name = name
ops.fSet = flag.NewFlagSet(name, flag.ContinueOnError)
// disable output internal error message on parse flags
Expand Down
13 changes: 13 additions & 0 deletions gflag/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ func New(nameWithDesc ...string) *Parser {
return p
}

// InitParser for parser
func (p *Parser) InitParser(name string) {
if p.out == nil {
p.out = os.Stdout
}
if p.cfg == nil {
p.cfg = newDefaultFlagConfig()
}

p.SetName(name)
p.InitFlagSet(name)
}

// SetName for parser
func (p *Parser) SetName(name string) {
p.name = name
Expand Down

0 comments on commit 4c7ed4b

Please sign in to comment.