Arbitrary CLI flags parser, like argparse in Python.
Go to file
Vladimir Hodakov a41a779d43
Use go modules
2019-09-28 18:44:09 +04:00
.vscode Test fix. 2018-12-04 15:50:01 +05:00
example Added example program, New() now requires application name, fixed -h and -help. 2018-12-18 04:02:01 +05:00
vendor Use go modules 2019-09-28 18:44:09 +04:00
.gitignore Initial commit. 2017-08-20 14:59:51 +05:00
.gitlab-ci.yml Gitlab CI configuration fix. 2018-12-18 04:10:54 +05:00
.travis.yml Relicensed under MIT. 2018-03-23 08:14:25 +05:00
LICENSE Relicensed under MIT. 2018-03-23 08:14:25 +05:00
README.md We have a mailing list now! 2019-01-22 17:38:36 +05:00
exported.go Added example program, New() now requires application name, fixed -h and -help. 2018-12-18 04:02:01 +05:00
flag.go Test fix. 2018-12-04 15:50:01 +05:00
flagger.go Exit immediately if -h or -help was passed. 2018-12-18 04:21:13 +05:00
flagger_test.go Fixed tests. 2018-12-18 04:04:57 +05:00
gitlab-ci.yml CI fix. 2018-11-28 08:42:41 +05:00
go.mod Use go modules 2019-09-28 18:44:09 +04:00
go.sum Use go modules 2019-09-28 18:44:09 +04: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

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("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.

Get help

If you want to report a bug - feel free to report it via Gitlab's issues system. Note that everything that isn't a bug report or feature request will be closed without any futher comments.

If you want to request some help (without warranties), propose a feature request or discuss flagger in any way - please use our mailing lists at flagger@googlegroups.com. To be able to send messages there you should subscribe by sending email to flagger+subscribe@googlegroups.com, subject and mail body can be random.