Command line flags made simple
go get -u github.com/libgolang/props
import (
"fmt"
"github.com/libgolang/props"
)
func main() {
if props.IsSet("name") {
fmt.Printf("My Name is %s\n", props.GetProp("name"))
} else {
fmt.Printf("No name given\n")
}
}
- Does not require pre-defining properties. It dynamically figures out properties based on
os.Args
- Does no require 3rd party libraries
- Just three functions
GetProp
,IsSet
andGetArgs
- Arguments with two dashes and an equal sign are interpreted as properties with a value.
e.g.:
--prop-name=value
- Arguments with two dashes and NO equal sign will interpret the next argument as a value.
If no argument is followed by the property, then it will have an empty value.
e.g.:
--prop-name value
thenGetProp("prop-name"): "value"
and--prop-name --some-other-property
thenGetProp("prop-name"): ""
- Arguments with one dash are interperted as Flags. If a value is passed to the flag it is igned and used as an argument in
GetArgs()
. e.g.:-p
thenIsSet("p") : true
- Any argument not part of a flag or a property is added to the argument list and they can be retrived by calling
GetArgs()
.