Fork of spf13/pflag aimed to provide support for non-posix variants in carapace standalone mode (e.g. carapace-bin).
Support shorthand-only flags (e.g. -h
without --help
) using S
suffix for flag functions:
pflag.BoolS("help", "h", false, "show help") // -h
Support shorthand flags that are more than one character long (e.g. pkill -<sig>
).
This implicitly disables posix shorthand chaining (e.g.
ls -lha
):
pflag.BoolS("STOP", "STOP", false, "Stop process, unblockable") // -STOP
pflag.BoolN("help", "h", false, "show help") // -h, -help
Support custom optarg delimiter (e.g. java -agentlib:jdwp
).
rootCmd.Flags().StringS("agentlib", "agentlib", "", "load native agent library")
rootCmd.Flag("agentlib").NoOptDefVal = " "
rootCmd.Flag("agentlib").OptargDelimiter = ':'
Support for flags consuming multiple arguments.
Use with
Slice
andArray
flag types.
rootCmd.Flags().StringSlice("nargs-any", []string{}, "Nargs")
rootCmd.Flags().StringSlice("nargs-two", []string{}, "Nargs")
rootCmd.Flag("nargs-any").Nargs = -1 // consumes at least one argument until one starts with `-`
rootCmd.Flag("nargs-two").Nargs = 2 // consumes exactly 2 arguments