Arbitrary CLI flags parser, like argparse in Python.
Go to file
Stanislav N. aka pztrn afcd13f1ef
Some checks failed
continuous-integration/drone/push Build is failing
Switch to mirrorred images for Drone and make linters happy.
2022-06-29 16:35:24 +05:00
example Drone, linter improvements. 2020-06-18 00:33:09 +05:00
.drone.yml Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
.gitignore gitignore and Drone configuration updates. 2021-11-20 03:53:33 +05:00
.golangci.yml Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
errors.go Drone, linter improvements. 2020-06-18 00:33:09 +05:00
exported.go Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
flag.go Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
flagger_test.go Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
flagger.go Switch to mirrorred images for Drone and make linters happy. 2022-06-29 16:35:24 +05:00
go.mod Drone, linter improvements. 2020-06-18 00:33:09 +05:00
go.sum Drone, linter improvements. 2020-06-18 00:33:09 +05:00
LICENSE Moved to my Gitea, switched to Drone CI, removed vendor, updated README. 2019-10-15 21:20:49 +05:00
loggerinterface.go Moved to my Gitea, switched to Drone CI, removed vendor, updated README. 2019-10-15 21:20:49 +05:00
README.md Linting. 2019-12-22 01:29:18 +05:00

Flagger

GoDoc Drone (self-hosted) Discord Keybase XLM Go Report Card

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.