Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
package main
import "github.com/integrii/flaggy"
func main() {
// Declare variables and their defaults
var stringFlag = "defaultValue"
// Create the subcommand
subcommand := flaggy.NewSubcommand("subcommandExample")
// Add a flag to the subcommand
subcommand.String(&stringFlag, "f", "flag", "A test string flag")
// Add the subcommand to the parser at position 1
flaggy.AttachSubcommand(subcommand, 1)
// Parse the subcommand and all flags
flaggy.Parse()
// Use the flag
println(stringFlag)
}
when calling this by % ./main -f a, it shows the following error:
mymain
Usage:
mymain [subcommandExample]
Subcommands:
subcommandExample
Flags:
--version Displays the program version string.
-h --help Displays help with available flag, subcommand, and positional value parameters.
Unknown arguments supplied: f a
so, is there any option to show the error as Unknown arguments supplied: -f a instead of Unknown arguments supplied: f a? I.e, replacing the empty space before f by the - symbol.
Edit: the same for Expected a following arg for flag f, but it did not exist, it would be nice an option to show Expected a following arg for flag -f, but it did not exist instead, and Expected a following arg for flag --flag, but it did not exist instead of Expected a following arg for flag flag, but it did not exist, and so on.
Hi.
Consider the following example:
when calling this by
% ./main -f a
, it shows the following error:so, is there any option to show the error as
Unknown arguments supplied: -f a
instead ofUnknown arguments supplied: f a
? I.e, replacing the empty space beforef
by the-
symbol.Edit: the same for
Expected a following arg for flag f, but it did not exist
, it would be nice an option to showExpected a following arg for flag -f, but it did not exist
instead, andExpected a following arg for flag --flag, but it did not exist
instead ofExpected a following arg for flag flag, but it did not exist
, and so on.TIA