A commandline parser in go. Single and multi-character option names with - and -- switches. Decent formatted Usage() output.
License
welterde/go-pkg-optarg
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
OPTARG - A simple commandline options parser. - Allows options with single and multi character names according to the traditional unix way of doing things. eg: -o versus --option - Exposes a channel based iterator which returns parsed options from the optarg.Parse() function. Note that it only yields Options which are actually present in the commandline arguments (os.Args). Call as a for loop: for opt := range optarg.Parse() { // ... parse option } - Standard switch tokens are - and --. Can be modified by changing the vars optarg.ShortSwitch and optarg.LongSwitch. - Any arguments not associated with an option will be available in the optarg.Remainder slice after optarg.Parse() has been run. - Boolean flags require no value. The precense or absence of the flag is the value by itself. eg: flag '-n' is false if it's not found in os.Args, true if it is. - Exposes a Usage() function which prints options with their description and default values to the standard output. As opposed to the flag package, this outputs *neatly formatted* text. It prints output like the following. Note that this is the Usage() output of the options listed in optarg_test.go. It uses my own sexy multilineWrap() routine (see string.go): -------------------------------------------------------------------------------- Usage: ./6.out [options]: --source, -s: Path to the source folder. Here is some added description information which is completely useless, but it makes sure we can pimp our sexy Usage() output when dealing with lenghty, multi -line description texts. --bin, -b: Path to the binary folder. --arch, -a: Target architecture. (defaults to: amd64) --noproc, -n: Skip pre/post processing. (defaults to: false) --purge, -p: Clean compiled packages after linking is complete. (defaults to: false) -------------------------------------------------------------------------------- - Specify arguments to options using whitespace. This is *not* accepted: -f=bar -fBar This *is* accepted: -f bar -f "bar" - We support chaining shortform options together like this: -mnopq This considers each letter as a separate option. The last one can even have an argument if it needs one: -mnopq "foo"
About
A commandline parser in go. Single and multi-character option names with - and -- switches. Decent formatted Usage() output.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published