Skip to content

Instantly share code, notes, and snippets.

@topjor
Created January 28, 2020 10:46
Show Gist options
  • Save topjor/51e52e88e2c7aedb4d5b34c21497d1a1 to your computer and use it in GitHub Desktop.
Save topjor/51e52e88e2c7aedb4d5b34c21497d1a1 to your computer and use it in GitHub Desktop.
Positional values
./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
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