Linting.
This commit is contained in:
parent
f7e1a38e28
commit
e81ce2c830
26
README.md
26
README.md
@ -1,31 +1,31 @@
|
|||||||
[![GoDoc](https://godoc.org/go.dev.pztrn.name/flagger?status.svg)](https://godoc.org/go.dev.pztrn.name/flagger) [![Drone (self-hosted)](https://img.shields.io/drone/build/libraries/flagger?server=https%3A%2F%2Fci.dev.pztrn.name)](https://ci.dev.pztrn.name/libraries/flagger/) [![Discord](https://img.shields.io/discord/632359730089689128)](https://discord.gg/qHN6KsD) ![Keybase XLM](https://img.shields.io/keybase/xlm/pztrn) [![Go Report Card](https://goreportcard.com/badge/go.dev.pztrn.name/flagger)](https://goreportcard.com/report/go.dev.pztrn.name/flagger)
|
|
||||||
|
|
||||||
# Flagger
|
# Flagger
|
||||||
|
|
||||||
|
[![GoDoc](https://godoc.org/go.dev.pztrn.name/flagger?status.svg)](https://godoc.org/go.dev.pztrn.name/flagger) [![Drone (self-hosted)](https://img.shields.io/drone/build/libraries/flagger?server=https%3A%2F%2Fci.dev.pztrn.name)](https://ci.dev.pztrn.name/libraries/flagger/) [![Discord](https://img.shields.io/discord/632359730089689128)](https://discord.gg/qHN6KsD) ![Keybase XLM](https://img.shields.io/keybase/xlm/pztrn) [![Go Report Card](https://goreportcard.com/badge/go.dev.pztrn.name/flagger)](https://goreportcard.com/report/go.dev.pztrn.name/flagger)
|
||||||
|
|
||||||
Flagger is an arbitrary CLI flags parser, like argparse in Python.
|
Flagger is an arbitrary CLI flags parser, like argparse in Python.
|
||||||
Flagger is able to parse boolean, integer and string flags.
|
Flagger is able to parse boolean, integer and string flags.
|
||||||
|
|
||||||
# Installation
|
## Installation
|
||||||
|
|
||||||
```
|
```bash
|
||||||
go get -u -v go.dev.pztrn.name/flagger
|
go get -u -v go.dev.pztrn.name/flagger
|
||||||
```
|
```
|
||||||
|
|
||||||
# Usage
|
## Usage
|
||||||
|
|
||||||
Flagger requires logging interface to be passed on initialization.
|
Flagger requires logging interface to be passed on initialization.
|
||||||
See ``loggerinterface.go`` for required logging functions.
|
See ``loggerinterface.go`` for required logging functions.
|
||||||
It is able to run with standart log package, in that case
|
It is able to run with standart log package, in that case
|
||||||
initialize flagger like:
|
initialize flagger like:
|
||||||
|
|
||||||
```
|
```go
|
||||||
flgr = flagger.New("My Super Program", flagger.LoggerInterface(log.New(os.Stdout, "testing logger: ", log.Lshortfile)))
|
flgr = flagger.New("My Super Program", flagger.LoggerInterface(log.New(os.Stdout, "testing logger: ", log.Lshortfile)))
|
||||||
flgr.Initialize()
|
flgr.Initialize()
|
||||||
```
|
```
|
||||||
|
|
||||||
Adding a flag is easy, just fill ``Flag`` structure and pass to ``AddFlag()`` call:
|
Adding a flag is easy, just fill ``Flag`` structure and pass to ``AddFlag()`` call:
|
||||||
|
|
||||||
```
|
```go
|
||||||
flag_bool := Flag{
|
flag_bool := Flag{
|
||||||
Name: "boolflag",
|
Name: "boolflag",
|
||||||
Description: "Boolean flag",
|
Description: "Boolean flag",
|
||||||
@ -41,23 +41,17 @@ if err != nil {
|
|||||||
After adding all neccessary flags you should issue ``Parse()`` call to get
|
After adding all neccessary flags you should issue ``Parse()`` call to get
|
||||||
them parsed:
|
them parsed:
|
||||||
|
|
||||||
```
|
```go
|
||||||
flgr.Parse()
|
flgr.Parse()
|
||||||
```
|
```
|
||||||
|
|
||||||
After parsed they can be obtained everywhere you want, like:
|
After parsed they can be obtained everywhere you want, like:
|
||||||
|
|
||||||
```
|
```go
|
||||||
val, err := flgr.GetBoolValue("boolflag")
|
val, err := flgr.GetBoolValue("boolflag")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For more examples take a look at ``flagger_test.go`` file or [at GoDoc](https://godoc.org/gitlab.com/pztrn/flagger).
|
For more examples take a look at ``flagger_test.go`` file or [at GoDoc](https://godoc.org/go.dev.pztrn.name/flagger).
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
@ -9,7 +9,7 @@ var f *flagger.Flagger
|
|||||||
func main() {
|
func main() {
|
||||||
f = flagger.New("testprogram", nil)
|
f = flagger.New("testprogram", nil)
|
||||||
f.Initialize()
|
f.Initialize()
|
||||||
f.AddFlag(&flagger.Flag{
|
_ = f.AddFlag(&flagger.Flag{
|
||||||
Name: "testflag",
|
Name: "testflag",
|
||||||
Description: "Just a test flag",
|
Description: "Just a test flag",
|
||||||
Type: "bool",
|
Type: "bool",
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flagger implements (kinda) extended CLI parameters parser. As it
|
// Flagger implements (kinda) extended CLI parameters parser. As it
|
||||||
@ -39,8 +38,7 @@ import (
|
|||||||
// parse or get.
|
// parse or get.
|
||||||
type Flagger struct {
|
type Flagger struct {
|
||||||
// Flags that was added by user.
|
// Flags that was added by user.
|
||||||
flags map[string]*Flag
|
flags map[string]*Flag
|
||||||
flagsMutex sync.Mutex
|
|
||||||
|
|
||||||
// Flags that will be passed to flag module.
|
// Flags that will be passed to flag module.
|
||||||
flagsBool map[string]*bool
|
flagsBool map[string]*bool
|
||||||
|
3
go.mod
3
go.mod
@ -3,7 +3,6 @@ module go.dev.pztrn.name/flagger
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/stretchr/testify v1.2.2
|
github.com/stretchr/testify v1.2.2
|
||||||
|
gitlab.com/pztrn/flagger v0.0.0-20191015160147-a9ca273d8b73
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -4,3 +4,5 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
gitlab.com/pztrn/flagger v0.0.0-20191015160147-a9ca273d8b73 h1:3wo+sJrNguob5mLnQQmH2/Rh2oCuEhIplgWpAMutFzY=
|
||||||
|
gitlab.com/pztrn/flagger v0.0.0-20191015160147-a9ca273d8b73/go.mod h1:I+FxZN2hnd4iELlBFizaDD4QJy92x6Ky4+76U7L3gBQ=
|
||||||
|
Loading…
Reference in New Issue
Block a user