Skip to content

Drop-in replacement for spf13/pflag with support for non-posix variants

License

Notifications You must be signed in to change notification settings

carapace-sh/carapace-pflag

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

carapace-pflag

PkgGoDev GoReportCard Coverage Status

Fork of spf13/pflag aimed to provide support for non-posix variants in carapace standalone mode (e.g. carapace-bin).

Customizations

Shorthand-Only

Support shorthand-only flags (e.g. -h without --help) using S suffix for flag functions:

pflag.BoolS("help", "h", false, "show help") // -h

Long Shorthand

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

Custom Optarg Delimiter

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 = ':'

Nargs

Support for flags consuming multiple arguments.

Use with Slice and Array 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

About

Drop-in replacement for spf13/pflag with support for non-posix variants

Resources

License

Stars

Watchers

Forks

Languages

  • Go 100.0%