Skip to content

Commit 35a7278

Browse files
authored
💝 Generate images (#1)
* Switch to wavesoftware/commandline * Generate images skel * Use dockerfilegen from o-k/hack * Fix lint * Use config values to gen images
1 parent aa2eed4 commit 35a7278

26 files changed

+3265
-453
lines changed

.golangci.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run:
33
build-tags:
44
- e2e
55
- mage
6+
- ignored
67

78
linters:
89
disable-all: false
@@ -18,31 +19,24 @@ linters:
1819
disable:
1920
- paralleltest
2021
- nlreturn
21-
- exhaustivestruct
2222
- wsl
2323
- godox
24-
- scopelint
25-
- maligned
26-
- interfacer
27-
- golint
24+
- ireturn
25+
- varnamelen
2826
- exhaustruct
29-
- containedctx
3027
- depguard
28+
- containedctx # TODO: consider removing this
3129

3230
issues:
3331
exclude-rules:
3432
- path: _test\.go
3533
linters:
3634
- wrapcheck
37-
- varnamelen
3835

3936
linters-settings:
40-
varnamelen:
41-
max-distance: 16
42-
min-name-length: 2
43-
37+
wrapcheck:
38+
ignorePackageGlobs:
39+
- github.com/openshift-knative/hack/*
4440
gomoddirectives:
4541
# List of allowed `replace` directives. Default is empty.
46-
replace-allow-list:
47-
# FIXME: until github.com/cli/cli requires forked github.com/cli/shurcooL-graphql
48-
- github.com/shurcooL/graphql
42+
replace-allow-list: []

build/Magefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// Default target is set to binary.
1919
//
2020
//goland:noinspection GoUnusedGlobalVariable
21-
var Default = magetasks.Build // nolint:deadcode,gochecknoglobals
21+
var Default = magetasks.Build //nolint:deadcode,gochecknoglobals
2222

2323
func init() { //nolint:gochecknoinits
2424
bin := artifact.Binary{

build/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/openshift-knative/deviate/build
22

3-
go 1.22.7
3+
go 1.22.9
44

55
require (
66
github.com/openshift-knative/deviate v0.0.0

cmd/deviate/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package main
22

33
import (
4-
"os"
5-
64
"github.com/openshift-knative/deviate/internal/cmd"
7-
)
8-
9-
var (
10-
exitFunc = os.Exit //nolint:gochecknoglobals
11-
opts []cmd.Option //nolint:gochecknoglobals
5+
"github.com/wavesoftware/go-commandline"
126
)
137

148
func main() {
15-
exitFunc(cmd.Main(opts...))
9+
commandline.New(new(cmd.App)).ExecuteOrDie(cmd.Options...)
1610
}

cmd/deviate/main_test.go

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,35 @@ import (
88
"github.com/openshift-knative/deviate/internal/cmd"
99
"github.com/openshift-knative/deviate/pkg/metadata"
1010
"github.com/spf13/cobra"
11+
"github.com/wavesoftware/go-commandline"
1112
"gotest.tools/v3/assert"
1213
)
1314

14-
const notSetRetCode = -1 * (2 ^ 63)
15-
1615
func TestMainFunc(t *testing.T) {
17-
o := output{}
18-
a := args{[]string{"--version"}}
19-
code := withCapturedRetCode(func() {
20-
withOptions(func() {
21-
main()
22-
}, o.configure, a.configure)
23-
})
24-
25-
assert.Equal(t, code, 0)
16+
var o bytes.Buffer
17+
var retcode *int
18+
withOptions(func() {
19+
main()
20+
},
21+
commandline.WithCommand(func(cmd *cobra.Command) {
22+
cmd.SetArgs([]string{"--version"})
23+
cmd.SetOut(&o)
24+
}),
25+
commandline.WithExit(func(code int) {
26+
retcode = &code
27+
}),
28+
)
29+
30+
assert.Equal(t, retcode, (*int)(nil))
2631
assert.Equal(t, o.String(), fmt.Sprintf("%s version %s\n",
2732
metadata.Name, metadata.Version))
2833
}
2934

30-
type args struct {
31-
of []string
32-
}
33-
34-
func (a args) configure(root *cobra.Command) {
35-
root.SetArgs(a.of)
36-
}
37-
38-
type output struct {
39-
*bytes.Buffer
40-
}
41-
42-
func (o *output) configure(root *cobra.Command) {
43-
root.SetOut(o.buff())
44-
root.SetErr(o.buff())
45-
}
46-
47-
func (o *output) buff() *bytes.Buffer {
48-
if o.Buffer == nil {
49-
o.Buffer = new(bytes.Buffer)
50-
}
51-
return o.Buffer
52-
}
53-
54-
func withCapturedRetCode(fn func()) int {
55-
retcode := notSetRetCode
56-
old := exitFunc
57-
exitFunc = func(code int) {
58-
retcode = code
59-
}
60-
defer func() {
61-
exitFunc = old
62-
}()
63-
fn()
64-
return retcode
65-
}
66-
67-
func withOptions(fn func(), newOpts ...cmd.Option) {
68-
old := opts
69-
opts = newOpts
35+
func withOptions(fn func(), newOpts ...commandline.Option) {
36+
old := cmd.Options
37+
cmd.Options = newOpts
7038
defer func() {
71-
opts = old
39+
cmd.Options = old
7240
}()
7341
fn()
7442
}

0 commit comments

Comments
 (0)