Skip to content

Commit

Permalink
feat: Expose leftover args so that can processed further if needed. (#46
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zoido authored Dec 10, 2023
1 parent c7aed04 commit a2ec721
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,8 @@ func (y *Parser) Usage() string {
}
return strings.Join(u, "\n")
}

// Args returns non-flag arguments left over after parsing.
func (y *Parser) Args() []string {
return y.flagSet.Args()
}
16 changes: 16 additions & 0 deletions parser_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ func ExampleErrHelp() {

// Output: --help flag passed
}

func ExampleParser_Args() {
var foo string

y := yag.New()

y.String(&foo, "foo", "sets Foo")
err := y.Parse([]string{"--foo", "x", "arg1", "arg2", "arg3"})
if err != nil {
fmt.Printf("error: %s", err)
}

fmt.Printf("foo: %q, args: %v", foo, y.Args())

// Output: foo: "x", args: [arg1 arg2 arg3]
}

0 comments on commit a2ec721

Please sign in to comment.