Drone, linter improvements.

This commit is contained in:
Stanislav Nikitin 2020-06-18 00:33:09 +05:00
parent 22e5e16021
commit 89bc9818b7
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
7 changed files with 77 additions and 17 deletions

View File

@ -1,11 +1,13 @@
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: build name: test-and-lint
steps: steps:
- name: notify-start - name: notify-start
image: pztrn/discordrone image: pztrn/discordrone
when:
instance: ci.dev.pztrn.name
settings: settings:
webhook_id: webhook_id:
from_secret: discord_webhook_id from_secret: discord_webhook_id
@ -16,16 +18,25 @@ steps:
- name: lint - name: lint
image: golangci/golangci-lint:latest image: golangci/golangci-lint:latest
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: "0"
commands: commands:
- golangci-lint run - golangci-lint run
depends_on: depends_on:
- notify-start - notify-start
- name: test-1.13 - name: test-1.14
image: golang:1.13.5-alpine image: golang:1.14.4-alpine
environment: 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: commands:
- go test -cover -test.v . - go test -cover -test.v .
depends_on: depends_on:
@ -33,6 +44,7 @@ steps:
- name: notify-end - name: notify-end
when: when:
instance: ci.dev.pztrn.name
status: status:
- success - success
- failure - failure
@ -51,3 +63,4 @@ steps:
depends_on: depends_on:
- lint - lint
- test-1.13 - test-1.13
- test-1.14

View File

@ -15,4 +15,9 @@ linters-settings:
line-length: 420 line-length: 420
gocyclo: gocyclo:
min-complexity: 40 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
View 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")
)

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"gitlab.com/pztrn/flagger" "go.dev.pztrn.name/flagger"
) )
var f *flagger.Flagger var f *flagger.Flagger

View File

@ -25,7 +25,7 @@ package flagger
import ( import (
// stdlib // stdlib
"errors"
"flag" "flag"
"os" "os"
) )
@ -52,7 +52,7 @@ type Flagger struct {
func (f *Flagger) AddFlag(flag *Flag) error { func (f *Flagger) AddFlag(flag *Flag) error {
_, present := f.flags[flag.Name] _, present := f.flags[flag.Name]
if present { if present {
return errors.New("Cannot add flag '" + flag.Name + "' - already added!") return ErrFlagAlreadyAdded
} }
f.flags[flag.Name] = flag f.flags[flag.Name] = flag
@ -66,7 +66,7 @@ func (f *Flagger) AddFlag(flag *Flag) error {
func (f *Flagger) GetBoolValue(name string) (bool, error) { func (f *Flagger) GetBoolValue(name string) (bool, error) {
fl, present := f.flagsBool[name] fl, present := f.flagsBool[name]
if !present { if !present {
return false, errors.New("No such flag: " + name) return false, ErrNoSuchFlag
} }
return (*fl), nil return (*fl), nil
@ -77,7 +77,7 @@ func (f *Flagger) GetBoolValue(name string) (bool, error) {
func (f *Flagger) GetIntValue(name string) (int, error) { func (f *Flagger) GetIntValue(name string) (int, error) {
fl, present := f.flagsInt[name] fl, present := f.flagsInt[name]
if !present { if !present {
return 0, errors.New("No such flag: " + name) return 0, ErrNoSuchFlag
} }
return (*fl), nil return (*fl), nil
@ -88,7 +88,7 @@ func (f *Flagger) GetIntValue(name string) (int, error) {
func (f *Flagger) GetStringValue(name string) (string, error) { func (f *Flagger) GetStringValue(name string) (string, error) {
fl, present := f.flagsString[name] fl, present := f.flagsString[name]
if !present { if !present {
return "", errors.New("No such flag: " + name) return "", ErrNoSuchFlag
} }
return (*fl), nil return (*fl), nil

3
go.mod
View File

@ -3,5 +3,6 @@ module go.dev.pztrn.name/flagger
go 1.13 go 1.13
require ( 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
View File

@ -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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
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/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gitlab.com/pztrn/flagger v0.0.0-20191015160147-a9ca273d8b73 h1:3wo+sJrNguob5mLnQQmH2/Rh2oCuEhIplgWpAMutFzY= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
gitlab.com/pztrn/flagger v0.0.0-20191015160147-a9ca273d8b73/go.mod h1:I+FxZN2hnd4iELlBFizaDD4QJy92x6Ky4+76U7L3gBQ= 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=