-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from integrii/remotes/origin/trailingArgs
Fix trailing arguments being considered errant positionals
- Loading branch information
Showing
6 changed files
with
118 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
trailingArguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/integrii/flaggy" | ||
) | ||
|
||
func main() { | ||
|
||
// Declare variables and their defaults | ||
var someString = "" | ||
var someInt = 3 | ||
var someBool bool | ||
var positionalValue string | ||
|
||
// 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") | ||
|
||
// this positional value will be parsed specifically before all trailing | ||
// arguments are parsed | ||
flaggy.AddPositionalValue(&positionalValue, "testPositional", 1, false, "a test positional") | ||
|
||
flaggy.DebugMode = false | ||
flaggy.ShowHelpOnUnexpectedDisable() | ||
|
||
// Parse the subcommand and all flags | ||
flaggy.Parse() | ||
|
||
// here you will see all arguments passsed after the first positional 'testPositional' string is parsed | ||
fmt.Println(flaggy.TrailingArguments) | ||
// Input: | ||
// ./trailingArguments one two three | ||
// Output: | ||
// [two three] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters