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: steps:
- name: lint - name: lint
image: golangci/golangci-lint:latest image: code.pztrn.name/containers/mirror/golangci/golangci-lint:v1.46.2
environment: environment:
CGO_ENABLED: "0" CGO_ENABLED: "0"
commands: commands:
- golangci-lint run - golangci-lint run
- name: test-1.14 - name: test-1.18
image: golang:1.14.4-alpine image: code.pztrn.name/containers/mirror/golang:1.18.3-alpine
environment: environment:
CGO_ENABLED: "0" CGO_ENABLED: "0"
commands: commands:
- go test -cover -test.v . - 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 - gocritic
# Complains about main() lengths, which isn't an issue. # Complains about main() lengths, which isn't an issue.
- funlen - funlen
- varnamelen
- paralleltest
# Deprecated.
- exhaustivestruct
linters-settings: linters-settings:
lll: lll:
line-length: 420 line-length: 420

View File

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

View File

@ -25,12 +25,12 @@ package flagger
// Flag represents addable flag for Flagger. // Flag represents addable flag for Flagger.
type Flag struct { type Flag struct {
// This value will be reflected.
DefaultValue interface{}
// Flag name. It will be accessible using this name later. // Flag name. It will be accessible using this name later.
Name string Name string
// Description for help output. // Description for help output.
Description string Description string
// Type can be one of "bool", "int", "string". // Type can be one of "bool", "int", "string".
Type string Type string
// This value will be reflected.
DefaultValue interface{}
} }

View File

@ -24,8 +24,6 @@
package flagger package flagger
import ( import (
// stdlib
"flag" "flag"
"os" "os"
) )
@ -50,8 +48,7 @@ type Flagger struct {
// AddFlag adds flag to list of flags we will pass to ``flag`` package. // AddFlag adds flag to list of flags we will pass to ``flag`` package.
func (f *Flagger) AddFlag(flag *Flag) error { func (f *Flagger) AddFlag(flag *Flag) error {
_, present := f.flags[flag.Name] if _, present := f.flags[flag.Name]; present {
if present {
return ErrFlagAlreadyAdded return ErrFlagAlreadyAdded
} }
@ -117,16 +114,17 @@ func (f *Flagger) Parse() {
} }
for name, fl := range f.flags { for name, fl := range f.flags {
if fl.Type == "bool" { switch fl.Type {
fdef := fl.DefaultValue.(bool) case "bool":
fdef, _ := fl.DefaultValue.(bool)
f.flagsBool[name] = &fdef f.flagsBool[name] = &fdef
f.flagSet.BoolVar(&fdef, name, fdef, fl.Description) f.flagSet.BoolVar(&fdef, name, fdef, fl.Description)
} else if fl.Type == "int" { case "int":
fdef := fl.DefaultValue.(int) fdef, _ := fl.DefaultValue.(int)
f.flagsInt[name] = &fdef f.flagsInt[name] = &fdef
f.flagSet.IntVar(&fdef, name, fdef, fl.Description) f.flagSet.IntVar(&fdef, name, fdef, fl.Description)
} else if fl.Type == "string" { case "string":
fdef := fl.DefaultValue.(string) fdef, _ := fl.DefaultValue.(string)
f.flagsString[name] = &fdef f.flagsString[name] = &fdef
f.flagSet.StringVar(&fdef, name, fdef, fl.Description) f.flagSet.StringVar(&fdef, name, fdef, fl.Description)
} }
@ -134,8 +132,7 @@ func (f *Flagger) Parse() {
logger.Print("Parsing CLI parameters:", os.Args) logger.Print("Parsing CLI parameters:", os.Args)
err := f.flagSet.Parse(os.Args[1:]) if err := f.flagSet.Parse(os.Args[1:]); err != nil {
if err != nil {
os.Exit(0) os.Exit(0)
} }
} }

View File

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