You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
continuous-integration/drone/push Build is failing
Details
|
12 months ago | |
---|---|---|
example | 3 years ago | |
.drone.yml | 12 months ago | |
.gitignore | 2 years ago | |
.golangci.yml | 12 months ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
errors.go | 3 years ago | |
exported.go | 12 months ago | |
flag.go | 12 months ago | |
flagger.go | 12 months ago | |
flagger_test.go | 12 months ago | |
go.mod | 3 years ago | |
go.sum | 3 years ago | |
loggerinterface.go | 4 years ago |
README.md
Flagger
Flagger is an arbitrary CLI flags parser, like argparse in Python. Flagger is able to parse boolean, integer and string flags.
Installation
go get -u -v go.dev.pztrn.name/flagger
Usage
Flagger requires logging interface to be passed on initialization.
See loggerinterface.go
for required logging functions.
It is able to run with standart log package, in that case
initialize flagger like:
flgr = flagger.New("My Super Program", flagger.LoggerInterface(log.New(os.Stdout, "testing logger: ", log.Lshortfile)))
flgr.Initialize()
Adding a flag is easy, just fill Flag
structure and pass to AddFlag()
call:
flag_bool := Flag{
Name: "boolflag",
Description: "Boolean flag",
Type: "bool",
DefaultValue: true,
}
err := flgr.AddFlag(&flag_bool)
if err != nil {
...
}
After adding all neccessary flags you should issue Parse()
call to get
them parsed:
flgr.Parse()
After parsed they can be obtained everywhere you want, like:
val, err := flgr.GetBoolValue("boolflag")
if err != nil {
...
}
For more examples take a look at flagger_test.go
file or at GoDoc.