Arbitrary CLI flags parser, like argparse in Python.
Go to file
Stanislav Nikitin 73b8a5dd2a CI fix. 2018-11-28 08:42:41 +05:00
.vscode Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
vendor/github.com Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
.gitignore Initial commit. 2017-08-20 14:59:51 +05:00
.gitlab-ci.yml Gitlab CI fix. 2018-11-28 08:41:57 +05:00
.travis.yml Relicensed under MIT. 2018-03-23 08:14:25 +05:00
Gopkg.lock Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
Gopkg.toml Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
LICENSE Relicensed under MIT. 2018-03-23 08:14:25 +05:00
README.md GoDoc link updated. 2018-03-23 08:28:03 +05:00
exported.go Allow to skip specifying logger so default log package will be used. 2018-04-27 13:25:27 +05:00
flag.go Relicensed under MIT. 2018-03-23 08:14:25 +05:00
flagger.go Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
flagger_test.go Moved from flag module singleton usage to FlagSet and fixed tests. 2018-11-28 08:40:04 +05:00
gitlab-ci.yml CI fix. 2018-11-28 08:42:41 +05:00
loggerinterface.go Fixed logger interface to be compatible with wider range of loggers. 2018-04-27 13:13:23 +05:00

README.md

GoDoc Build Status

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 lab.pztrn.name/golibs/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(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.