clop: github.com/mkmueller/clop Index | Files

package clop

import "github.com/mkmueller/clop"

Package clop is a Command Line Option Parser that does not require pre-defined flags or options, there are no default values and there is no help facility. Implementation is simple making flags, options, and arguments easily available with no setup.

In this package, a flag is defined as a single hyphen with a single alpha character, upper or lower case. If a hyphen prefixes several alpha characters, each one will be considered a separate flag. There is no way to set a flag false and you cannot assign a value to a flag. So `-f value` or `-f=value` will not work. Instead, they will be assigned to the Args array. The following command line example sets the individual flags A, b, and c.

Example:  command -Abc

Options are defined as a double-hyphen prefixed string followed by an optional equal symbol (=) and a value. Option values are strings. You'll have to handle type conversion and error checking yourself. Options are available using the IsOption and Option functions. The following command line example uses two options, with and without a value.

Example:  command --question --answer=42

All other command line arguments that are not interpreted as a flag or an option will be considered Args and are available directly in the Args array.

Example:  command Don't Panic

Index

Package Files

clop.go

Variables

var Args []string

Args is a string array that contains the remaining command line arguments that have not been interpreted as flags or options. Args[0] is the command itself.

var Flags map[string]bool

Flags is an array of Boolean values, one for each command line flag.

var HasArgs bool

HasArgs will be true if any flag option or argument was set.

var Options map[string]string

Options is a string map, one entry for each command line option.

Example:
if v,ok := clop.Options["answer"]; ok {
  fmt.Printf("The answer to the ultimate question is %s", v )
}
// Output: The answer to the ultimate question is 42

func Flag Uses

func Flag(k string) bool

Flag returns true if the flag was set.

Example:
if clop.Flag("A") {
  fmt.Println("The flag -A was set")
}

func Option Uses

func Option(k string) string

Option returns the value of a given option.

fmt.Printf("The answer to the ultimate question is %s", clop.Option("answer"))
// Output: The answer to the ultimate question is 42

Package clop imports 3 packages (graph). Updated 2017-10-22. Refresh now. Tools for package owners.