Drone, linter improvements.
This commit is contained in:
parent
22e5e16021
commit
89bc9818b7
23
.drone.yml
23
.drone.yml
@ -1,11 +1,13 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build
|
||||
name: test-and-lint
|
||||
|
||||
steps:
|
||||
- name: notify-start
|
||||
image: pztrn/discordrone
|
||||
when:
|
||||
instance: ci.dev.pztrn.name
|
||||
settings:
|
||||
webhook_id:
|
||||
from_secret: discord_webhook_id
|
||||
@ -16,16 +18,25 @@ steps:
|
||||
- name: lint
|
||||
image: golangci/golangci-lint:latest
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- golangci-lint run
|
||||
depends_on:
|
||||
- notify-start
|
||||
|
||||
- name: test-1.13
|
||||
image: golang:1.13.5-alpine
|
||||
- name: test-1.14
|
||||
image: golang:1.14.4-alpine
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go test -cover -test.v .
|
||||
depends_on:
|
||||
- notify-start
|
||||
|
||||
- name: test-1.13
|
||||
image: golang:1.13.12-alpine
|
||||
environment:
|
||||
CGO_ENABLED: "0"
|
||||
commands:
|
||||
- go test -cover -test.v .
|
||||
depends_on:
|
||||
@ -33,6 +44,7 @@ steps:
|
||||
|
||||
- name: notify-end
|
||||
when:
|
||||
instance: ci.dev.pztrn.name
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
@ -51,3 +63,4 @@ steps:
|
||||
depends_on:
|
||||
- lint
|
||||
- test-1.13
|
||||
- test-1.14
|
||||
|
@ -15,4 +15,9 @@ linters-settings:
|
||||
line-length: 420
|
||||
gocyclo:
|
||||
min-complexity: 40
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
# We do not want to enforce black-box testing.
|
||||
- path: flagger_test.go
|
||||
linters:
|
||||
- testpackage
|
||||
|
36
errors.go
Normal file
36
errors.go
Normal file
@ -0,0 +1,36 @@
|
||||
// Flagger - arbitrary CLI flags parser.
|
||||
//
|
||||
// Copyright (c) 2017-2019, 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 "errors"
|
||||
|
||||
var (
|
||||
// ErrFlagAlreadyAdded appears when trying to register a flag with
|
||||
// an already used name (field Name).
|
||||
ErrFlagAlreadyAdded = errors.New("flag already added")
|
||||
|
||||
// ErrNoSuchFlag appears when trying to request a value for a flag
|
||||
// that wasn't registered.
|
||||
ErrNoSuchFlag = errors.New("no such flag")
|
||||
)
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitlab.com/pztrn/flagger"
|
||||
"go.dev.pztrn.name/flagger"
|
||||
)
|
||||
|
||||
var f *flagger.Flagger
|
||||
|
10
flagger.go
10
flagger.go
@ -25,7 +25,7 @@ package flagger
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"errors"
|
||||
|
||||
"flag"
|
||||
"os"
|
||||
)
|
||||
@ -52,7 +52,7 @@ type Flagger struct {
|
||||
func (f *Flagger) AddFlag(flag *Flag) error {
|
||||
_, present := f.flags[flag.Name]
|
||||
if present {
|
||||
return errors.New("Cannot add flag '" + flag.Name + "' - already added!")
|
||||
return ErrFlagAlreadyAdded
|
||||
}
|
||||
|
||||
f.flags[flag.Name] = flag
|
||||
@ -66,7 +66,7 @@ func (f *Flagger) AddFlag(flag *Flag) 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 false, ErrNoSuchFlag
|
||||
}
|
||||
|
||||
return (*fl), nil
|
||||
@ -77,7 +77,7 @@ func (f *Flagger) GetBoolValue(name string) (bool, 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 0, ErrNoSuchFlag
|
||||
}
|
||||
|
||||
return (*fl), nil
|
||||
@ -88,7 +88,7 @@ func (f *Flagger) GetIntValue(name string) (int, error) {
|
||||
func (f *Flagger) GetStringValue(name string) (string, error) {
|
||||
fl, present := f.flagsString[name]
|
||||
if !present {
|
||||
return "", errors.New("No such flag: " + name)
|
||||
return "", ErrNoSuchFlag
|
||||
}
|
||||
|
||||
return (*fl), nil
|
||||
|
3
go.mod
3
go.mod
@ -3,5 +3,6 @@ module go.dev.pztrn.name/flagger
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/stretchr/testify v1.2.2
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
)
|
||||
|
13
go.sum
13
go.sum
@ -1,8 +1,13 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
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/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=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
Loading…
Reference in New Issue
Block a user