Skip to content

Commit

Permalink
new trailingArguments example
Browse files Browse the repository at this point in the history
  • Loading branch information
integrii committed May 27, 2022
1 parent 5f3540f commit a8c26c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/trailingArguments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailingArguments
27 changes: 27 additions & 0 deletions examples/trailingArguments/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"

"github.com/integrii/flaggy"
)

func main() {

// Declare variables and their defaults
var someString = ""
var someInt = 3
var someBool bool

// add a global bool flag for fun
flaggy.Bool(&someBool, "y", "yes", "A sample boolean flag")
flaggy.String(&someString, "s", "string", "A sample string flag")
flaggy.Int(&someInt, "i", "int", "A sample int flag")

flaggy.ShowHelpOnUnexpectedDisable()

// Parse the subcommand and all flags
flaggy.Parse()

fmt.Println(flaggy.TrailingArguments)
}
2 changes: 1 addition & 1 deletion helpValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (h *Help) parseFlagsToHelpFlags(flags []*Flag, maxLength int) {
_, isBool := f.AssignmentVar.(*bool)
if isBool {
b := f.AssignmentVar.(*bool)
if *b == false {
if !*b {
defaultValue = ""
}
}
Expand Down
2 changes: 1 addition & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestFindArgsNotInParsedValues(t *testing.T) {

// ensure regular values are not skipped
parsedValues = []parsedValue{
parsedValue{
{
Key: "flaggy",
Value: "testing",
},
Expand Down

0 comments on commit a8c26c0

Please sign in to comment.