Created
January 28, 2020 10:46
-
-
Save topjor/51e52e88e2c7aedb4d5b34c21497d1a1 to your computer and use it in GitHub Desktop.
Positional values
This file contains hidden or 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
./test | |
test | |
Usage: | |
test [start] [positionalVar] | |
Positional Variables: | |
positionalVar A test positional flag (Required) | |
Subcommands: | |
start Start | |
Flags: | |
--version Displays the program version string. | |
-h --help Displays help with available flag, subcommand, and positional value parameters. | |
Required global positional variable positionalVar not found at position 2 | |
./test start | |
start - Start | |
Flags: | |
--version Displays the program version string. | |
-h --help Displays help with available flag, subcommand, and positional value parameters. | |
Required global positional variable positionalVar not found at position 2 | |
./test start asdf | |
start - Start | |
Flags: | |
--version Displays the program version string. | |
-h --help Displays help with available flag, subcommand, and positional value parameters. | |
Unexpected argument: asdf |
This file contains hidden or 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
package main | |
import "github.com/integrii/flaggy" | |
func main() { | |
// add subcommand | |
scStart := flaggy.NewSubcommand("start") | |
scStart.Description = "Start" | |
flaggy.AttachSubcommand(scStart, 1) | |
// add a bool flag at the global level | |
var stringVar string | |
flaggy.AddPositionalValue(&stringVar, "positionalVar", 2, true, "A test positional flag") | |
// Parse the input arguments from the OS (os.Args) | |
flaggy.Parse() | |
flaggy.ShowHelp("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment