Initial commit
This commit is contained in:
1
vendor/gitlab.com/pztrn/flagger/.gitignore
generated
vendored
Normal file
1
vendor/gitlab.com/pztrn/flagger/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*DS_Store*
|
34
vendor/gitlab.com/pztrn/flagger/.gitlab-ci.yml
generated
vendored
Normal file
34
vendor/gitlab.com/pztrn/flagger/.gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
stages:
|
||||
- test
|
||||
|
||||
before_script:
|
||||
- mkdir -p ${GOPATH}/src/gitlab.com/pztrn/
|
||||
- ln -s $CI_PROJECT_DIR ${GOPATH}/src/gitlab.com/pztrn/flagger
|
||||
- cd ${GOPATH}/src/gitlab.com/pztrn/flagger
|
||||
|
||||
test:1.11:
|
||||
image: golang:1.11.3
|
||||
stage: test
|
||||
tags:
|
||||
- docker
|
||||
script:
|
||||
- pwd
|
||||
- go test -test.v -cover ./...
|
||||
|
||||
test:1.10:
|
||||
image: golang:1.10.6
|
||||
stage: test
|
||||
tags:
|
||||
- docker
|
||||
script:
|
||||
- pwd
|
||||
- go test -test.v -cover ./...
|
||||
|
||||
test:1.9:
|
||||
image: golang:1.9.7
|
||||
stage: test
|
||||
tags:
|
||||
- docker
|
||||
script:
|
||||
- pwd
|
||||
- go test -test.v -cover ./...
|
3
vendor/gitlab.com/pztrn/flagger/.travis.yml
generated
vendored
Normal file
3
vendor/gitlab.com/pztrn/flagger/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
language: go
|
||||
go:
|
||||
- "1.10"
|
36
vendor/gitlab.com/pztrn/flagger/Gopkg.lock
generated
vendored
Normal file
36
vendor/gitlab.com/pztrn/flagger/Gopkg.lock
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
pruneopts = "UT"
|
||||
revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
|
||||
version = "v1.1.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
packages = ["difflib"]
|
||||
pruneopts = "UT"
|
||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c40d65817cdd41fac9aa7af8bed56927bb2d6d47e4fea566a74880f5c2b1c41e"
|
||||
name = "github.com/stretchr/testify"
|
||||
packages = [
|
||||
"assert",
|
||||
"require",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
|
||||
version = "v1.2.2"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = ["github.com/stretchr/testify/require"]
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
34
vendor/gitlab.com/pztrn/flagger/Gopkg.toml
generated
vendored
Normal file
34
vendor/gitlab.com/pztrn/flagger/Gopkg.toml
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/stretchr/testify"
|
||||
version = "1.2.2"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
7
vendor/gitlab.com/pztrn/flagger/LICENSE
generated
vendored
Normal file
7
vendor/gitlab.com/pztrn/flagger/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2017-2018, Stanislav N. aka pztrn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
63
vendor/gitlab.com/pztrn/flagger/README.md
generated
vendored
Normal file
63
vendor/gitlab.com/pztrn/flagger/README.md
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
[](https://godoc.org/gitlab.com/pztrn/flagger)
|
||||
|
||||
# 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](https://godoc.org/gitlab.com/pztrn/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.
|
50
vendor/gitlab.com/pztrn/flagger/exported.go
generated
vendored
Normal file
50
vendor/gitlab.com/pztrn/flagger/exported.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// Flagger - arbitrary CLI flags parser.
|
||||
//
|
||||
// Copyright (c) 2017-2018, Stanislav N. aka pztrn.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject
|
||||
// to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
package flagger
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
logger LoggerInterface
|
||||
applicationName string
|
||||
)
|
||||
|
||||
// New creates new Flagger instance.
|
||||
// If no logger will be passed - we will use default "log" module and will
|
||||
// print logs to stdout.
|
||||
func New(appName string, l LoggerInterface) *Flagger {
|
||||
applicationName = appName
|
||||
if l == nil {
|
||||
lg := log.New(os.Stdout, "Flagger: ", log.LstdFlags)
|
||||
logger = LoggerInterface(lg)
|
||||
} else {
|
||||
logger = l
|
||||
}
|
||||
f := Flagger{}
|
||||
return &f
|
||||
}
|
36
vendor/gitlab.com/pztrn/flagger/flag.go
generated
vendored
Normal file
36
vendor/gitlab.com/pztrn/flagger/flag.go
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// Flagger - arbitrary CLI flags parser.
|
||||
//
|
||||
// Copyright (c) 2017-2018, Stanislav N. aka pztrn.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject
|
||||
// to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
package flagger
|
||||
|
||||
// Flag represents addable flag for Flagger.
|
||||
type Flag struct {
|
||||
// Flag name. It will be accessible using this name later.
|
||||
Name string
|
||||
// Description for help output.
|
||||
Description string
|
||||
// Type can be one of "bool", "int", "string".
|
||||
Type string
|
||||
// This value will be reflected.
|
||||
DefaultValue interface{}
|
||||
}
|
138
vendor/gitlab.com/pztrn/flagger/flagger.go
generated
vendored
Normal file
138
vendor/gitlab.com/pztrn/flagger/flagger.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
// Flagger - arbitrary CLI flags parser.
|
||||
//
|
||||
// Copyright (c) 2017-2018, Stanislav N. aka pztrn.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject
|
||||
// to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
package flagger
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
"flag"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Flagger implements (kinda) extended CLI parameters parser. As it
|
||||
// available from CommonContext, these flags will be available to
|
||||
// whole application.
|
||||
//
|
||||
// It uses reflection to determine what kind of variable we should
|
||||
// parse or get.
|
||||
type Flagger struct {
|
||||
// Flags that was added by user.
|
||||
flags map[string]*Flag
|
||||
flagsMutex sync.Mutex
|
||||
|
||||
// Flags that will be passed to flag module.
|
||||
flagsBool map[string]*bool
|
||||
flagsInt map[string]*int
|
||||
flagsString map[string]*string
|
||||
|
||||
flagSet *flag.FlagSet
|
||||
}
|
||||
|
||||
// AddFlag adds flag to list of flags we will pass to ``flag`` package.
|
||||
func (f *Flagger) AddFlag(flag *Flag) error {
|
||||
_, present := f.flags[flag.Name]
|
||||
if present {
|
||||
return errors.New("Cannot add flag '" + flag.Name + "' - already added!")
|
||||
}
|
||||
|
||||
f.flags[flag.Name] = flag
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBoolValue returns boolean value for flag with given name.
|
||||
// Returns bool value for flag and nil as error on success
|
||||
// and false bool plus error with text on error.
|
||||
func (f *Flagger) GetBoolValue(name string) (bool, error) {
|
||||
fl, present := f.flagsBool[name]
|
||||
if !present {
|
||||
return false, errors.New("No such flag: " + name)
|
||||
}
|
||||
return (*fl), nil
|
||||
}
|
||||
|
||||
// GetIntValue returns integer value for flag with given name.
|
||||
// Returns integer on success and 0 on error.
|
||||
func (f *Flagger) GetIntValue(name string) (int, error) {
|
||||
fl, present := f.flagsInt[name]
|
||||
if !present {
|
||||
return 0, errors.New("No such flag: " + name)
|
||||
}
|
||||
return (*fl), nil
|
||||
}
|
||||
|
||||
// GetStringValue returns string value for flag with given name.
|
||||
// Returns string on success or empty string on error.
|
||||
func (f *Flagger) GetStringValue(name string) (string, error) {
|
||||
fl, present := f.flagsString[name]
|
||||
if !present {
|
||||
return "", errors.New("No such flag: " + name)
|
||||
}
|
||||
return (*fl), nil
|
||||
}
|
||||
|
||||
// Initialize initializes Flagger.
|
||||
func (f *Flagger) Initialize() {
|
||||
logger.Print("Initializing CLI parameters parser...")
|
||||
|
||||
f.flags = make(map[string]*Flag)
|
||||
|
||||
f.flagsBool = make(map[string]*bool)
|
||||
f.flagsInt = make(map[string]*int)
|
||||
f.flagsString = make(map[string]*string)
|
||||
|
||||
f.flagSet = flag.NewFlagSet(applicationName, flag.ContinueOnError)
|
||||
}
|
||||
|
||||
// Parse adds flags from flags map to flag package and parse
|
||||
// them. They can be obtained later by calling GetTYPEValue(name),
|
||||
// where TYPE is one of Bool, Int, String.
|
||||
func (f *Flagger) Parse() {
|
||||
// If flags was already parsed - do nothing.
|
||||
if f.flagSet.Parsed() {
|
||||
return
|
||||
}
|
||||
|
||||
for name, fl := range f.flags {
|
||||
if fl.Type == "bool" {
|
||||
fdef := fl.DefaultValue.(bool)
|
||||
f.flagsBool[name] = &fdef
|
||||
f.flagSet.BoolVar(&fdef, name, fdef, fl.Description)
|
||||
} else if fl.Type == "int" {
|
||||
fdef := fl.DefaultValue.(int)
|
||||
f.flagsInt[name] = &fdef
|
||||
f.flagSet.IntVar(&fdef, name, fdef, fl.Description)
|
||||
} else if fl.Type == "string" {
|
||||
fdef := fl.DefaultValue.(string)
|
||||
f.flagsString[name] = &fdef
|
||||
f.flagSet.StringVar(&fdef, name, fdef, fl.Description)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Print("Parsing CLI parameters:", os.Args)
|
||||
err := f.flagSet.Parse(os.Args[1:])
|
||||
if err != nil {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
17
vendor/gitlab.com/pztrn/flagger/gitlab-ci.yml
generated
vendored
Normal file
17
vendor/gitlab.com/pztrn/flagger/gitlab-ci.yml
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
image: golang:1.11.1
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
||||
before_script:
|
||||
- mkdir -p ${GOPATH}/src/gitlab.com/pztrn/
|
||||
- ln -s $CI_PROJECT_DIR ${GOPATH}/src/gitlab.com/pztrn/flagger
|
||||
- cd ${GOPATH}/src/gitlab.com/pztrn/flagger
|
||||
|
||||
test:
|
||||
stage: test
|
||||
tags:
|
||||
- docker
|
||||
script:
|
||||
- pwd
|
||||
- go test -test.v -cover ./...
|
31
vendor/gitlab.com/pztrn/flagger/loggerinterface.go
generated
vendored
Normal file
31
vendor/gitlab.com/pztrn/flagger/loggerinterface.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Flagger - arbitrary CLI flags parser.
|
||||
//
|
||||
// Copyright (c) 2017-2018, Stanislav N. aka pztrn.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject
|
||||
// to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
package flagger
|
||||
|
||||
// LoggerInterface provide logging interface, so everyone can inject own
|
||||
// logging handlers.
|
||||
type LoggerInterface interface {
|
||||
Fatal(v ...interface{})
|
||||
Print(v ...interface{})
|
||||
}
|
Reference in New Issue
Block a user