Switch to mirrorred images for Drone and make linters happy.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Stanislav Nikitin 2022-06-29 16:35:24 +05:00
parent c010875aa3
commit afcd13f1ef
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
6 changed files with 20 additions and 28 deletions

View File

@ -5,23 +5,15 @@ name: test-and-lint
steps:
- name: lint
image: golangci/golangci-lint:latest
image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
environment:
CGO_ENABLED: "0"
commands:
- golangci-lint run
- name: test-1.14
image: golang:1.14.4-alpine
- name: test-1.18
image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
environment:
CGO_ENABLED: "0"
commands:
- go test -cover -test.v .
- name: test-1.13
image: golang:1.13.12-alpine
environment:
CGO_ENABLED: "0"
commands:
- go test -cover -test.v .

View File

@ -10,6 +10,10 @@ linters:
- gocritic
# Complains about main() lengths, which isn't an issue.
- funlen
- varnamelen
- paralleltest
# Deprecated.
- exhaustivestruct
linters-settings:
lll:
line-length: 420

View File

@ -24,7 +24,6 @@
package flagger
import (
// stdlib
"log"
"os"
)
@ -47,6 +46,7 @@ func New(appName string, l LoggerInterface) *Flagger {
logger = l
}
// nolint:exhaustruct
f := Flagger{}
return &f

View File

@ -25,12 +25,12 @@ package flagger
// Flag represents addable flag for Flagger.
type Flag struct {
// This value will be reflected.
DefaultValue interface{}
// 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{}
}

View File

@ -24,8 +24,6 @@
package flagger
import (
// stdlib
"flag"
"os"
)
@ -50,8 +48,7 @@ type Flagger struct {
// 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 {
if _, present := f.flags[flag.Name]; present {
return ErrFlagAlreadyAdded
}
@ -117,16 +114,17 @@ func (f *Flagger) Parse() {
}
for name, fl := range f.flags {
if fl.Type == "bool" {
fdef := fl.DefaultValue.(bool)
switch fl.Type {
case "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)
case "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)
case "string":
fdef, _ := fl.DefaultValue.(string)
f.flagsString[name] = &fdef
f.flagSet.StringVar(&fdef, name, fdef, fl.Description)
}
@ -134,8 +132,7 @@ func (f *Flagger) Parse() {
logger.Print("Parsing CLI parameters:", os.Args)
err := f.flagSet.Parse(os.Args[1:])
if err != nil {
if err := f.flagSet.Parse(os.Args[1:]); err != nil {
os.Exit(0)
}
}

View File

@ -24,12 +24,10 @@
package flagger
import (
// stdlib
"log"
"os"
"testing"
// other
"github.com/stretchr/testify/require"
)
@ -113,6 +111,7 @@ func TestFlaggerAddStringFlag(t *testing.T) {
err := f.AddFlag(&flagTestString)
require.Nil(t, err)
}
func TestFlaggerParse(t *testing.T) {
f := New("tests", LoggerInterface(log.New(os.Stdout, "testing logger: ", log.Lshortfile)))
require.NotNil(t, f)