Skip to content

Commit db3178c

Browse files
authored
Merge pull request #1954 from dragonchaser/kill_urfave
migrate from urfave/cli to spf13/cobra
2 parents 646b0ce + f465a2b commit db3178c

335 files changed

Lines changed: 19521 additions & 2469 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ go-mod-tidy:
198198
test:
199199
@go test -v -tags '$(TAGS)' -coverprofile coverage.out ./...
200200

201+
.PHONY: test-with-race
202+
test-with-race:
203+
@go test -race -v -tags '$(TAGS)' -coverprofile coverage.out ./...
204+
201205
.PHONY: go-coverage
202206
go-coverage:
203207
@if [ ! -f coverage.out ]; then $(MAKE) test &>/dev/null; fi;

go.mod

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ require (
7878
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af
7979
github.com/spf13/afero v1.15.0
8080
github.com/spf13/cobra v1.10.1
81+
github.com/spf13/pflag v1.0.10
82+
github.com/spf13/viper v1.21.0
8183
github.com/stretchr/testify v1.11.1
8284
github.com/test-go/testify v1.1.4
8385
github.com/testcontainers/testcontainers-go v0.40.0
@@ -88,7 +90,6 @@ require (
8890
github.com/tidwall/sjson v1.2.5
8991
github.com/tus/tusd/v2 v2.8.0
9092
github.com/unrolled/secure v1.16.0
91-
github.com/urfave/cli/v2 v2.27.7
9293
github.com/vmihailenco/msgpack/v5 v5.4.1
9394
github.com/xhit/go-simple-mail/v2 v2.16.0
9495
go-micro.dev/v4 v4.11.0
@@ -319,6 +320,7 @@ require (
319320
github.com/pablodz/inotifywaitgo v0.0.9 // indirect
320321
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
321322
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
323+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
322324
github.com/philhofer/fwd v1.2.0 // indirect
323325
github.com/pierrec/lz4/v4 v4.1.15 // indirect
324326
github.com/pjbgf/sha1cd v0.3.2 // indirect
@@ -335,6 +337,7 @@ require (
335337
github.com/russellhaering/goxmldsig v1.5.0 // indirect
336338
github.com/russross/blackfriday/v2 v2.1.0 // indirect
337339
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect
340+
github.com/sagikazarmark/locafero v0.11.0 // indirect
338341
github.com/samber/lo v1.51.0 // indirect
339342
github.com/samber/slog-common v0.19.0 // indirect
340343
github.com/samber/slog-zerolog/v2 v2.9.0 // indirect
@@ -350,10 +353,12 @@ require (
350353
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
351354
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92 // indirect
352355
github.com/skeema/knownhosts v1.3.0 // indirect
356+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
353357
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784 // indirect
354-
github.com/spf13/pflag v1.0.10 // indirect
358+
github.com/spf13/cast v1.10.0 // indirect
355359
github.com/stretchr/objx v0.5.2 // indirect
356360
github.com/studio-b12/gowebdav v0.9.0 // indirect
361+
github.com/subosito/gotenv v1.6.0 // indirect
357362
github.com/tchap/go-patricia/v2 v2.3.3 // indirect
358363
github.com/tidwall/match v1.1.1 // indirect
359364
github.com/tidwall/pretty v1.2.1 // indirect
@@ -362,6 +367,7 @@ require (
362367
github.com/tklauser/numcpus v0.8.0 // indirect
363368
github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 // indirect
364369
github.com/trustelem/zxcvbn v1.0.1 // indirect
370+
github.com/urfave/cli/v2 v2.27.5 // indirect
365371
github.com/valyala/fastjson v1.6.4 // indirect
366372
github.com/vektah/gqlparser/v2 v2.5.30 // indirect
367373
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

go.sum

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8
352352
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
353353
github.com/foxcpp/go-mockdns v1.1.0 h1:jI0rD8M0wuYAxL7r/ynTrCQQq0BVqfB99Vgk7DlmewI=
354354
github.com/foxcpp/go-mockdns v1.1.0/go.mod h1:IhLeSFGed3mJIAXPH2aiRQB+kqz7oqu8ld2qVbOu7Wk=
355+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
356+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
355357
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
356358
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
357359
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
@@ -988,6 +990,8 @@ github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2D
988990
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
989991
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
990992
github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
993+
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
994+
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
991995
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI=
992996
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
993997
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
@@ -1093,6 +1097,8 @@ github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK
10931097
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
10941098
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
10951099
github.com/sacloud/libsacloud v1.36.2/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg=
1100+
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
1101+
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
10961102
github.com/samber/lo v1.51.0 h1:kysRYLbHy/MB7kQZf5DSN50JHmMsNEdeY24VzJFu7wI=
10971103
github.com/samber/lo v1.51.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
10981104
github.com/samber/slog-common v0.19.0 h1:fNcZb8B2uOLooeYwFpAlKjkQTUafdjfqKcwcC89G9YI=
@@ -1142,6 +1148,8 @@ github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:s
11421148
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
11431149
github.com/smartystreets/gunit v1.0.4/go.mod h1:EH5qMBab2UclzXUcpR8b93eHsIlp9u+pDQIRp5DZNzQ=
11441150
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
1151+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
1152+
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
11451153
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784 h1:0jjO3HdJfOn6gYHD/ZNZh0LLMxEAqkYX7xoDPQReEgs=
11461154
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784/go.mod h1:ff/5myEGgtsAwf26goQCO905GrEm5ugEZSd6OWTsrhM=
11471155
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
@@ -1151,6 +1159,8 @@ github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
11511159
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
11521160
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
11531161
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
1162+
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
1163+
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
11541164
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
11551165
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
11561166
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
@@ -1163,6 +1173,8 @@ github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
11631173
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
11641174
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
11651175
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
1176+
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
1177+
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
11661178
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11671179
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11681180
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@@ -1184,6 +1196,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
11841196
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
11851197
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
11861198
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
1199+
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
1200+
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
11871201
github.com/tchap/go-patricia/v2 v2.3.3 h1:xfNEsODumaEcCcY3gI0hYPZ/PcpVv5ju6RMAhgwZDDc=
11881202
github.com/tchap/go-patricia/v2 v2.3.3/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
11891203
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
@@ -1225,8 +1239,8 @@ github.com/tus/tusd/v2 v2.8.0/go.mod h1:3/zEOVQQIwmJhvNam8phV4x/UQt68ZmZiTzeuJUN
12251239
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
12261240
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
12271241
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
1228-
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
1229-
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
1242+
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
1243+
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
12301244
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
12311245
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
12321246
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=

opencloud/pkg/command/backup.go

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,43 @@ import (
44
"errors"
55
"fmt"
66

7+
"github.com/spf13/cobra"
8+
79
"github.com/opencloud-eu/opencloud/opencloud/pkg/backup"
810
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
911
"github.com/opencloud-eu/opencloud/pkg/config"
1012
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
1113
"github.com/opencloud-eu/opencloud/pkg/config/parser"
1214
decomposedbs "github.com/opencloud-eu/reva/v2/pkg/storage/fs/decomposed/blobstore"
1315
decomposeds3bs "github.com/opencloud-eu/reva/v2/pkg/storage/fs/decomposeds3/blobstore"
14-
"github.com/urfave/cli/v2"
1516
)
1617

1718
// BackupCommand is the entrypoint for the backup command
18-
func BackupCommand(cfg *config.Config) *cli.Command {
19-
return &cli.Command{
20-
Name: "backup",
21-
Usage: "OpenCloud backup functionality",
22-
Subcommands: []*cli.Command{
23-
ConsistencyCommand(cfg),
24-
},
25-
Before: func(c *cli.Context) error {
19+
func BackupCommand(cfg *config.Config) *cobra.Command {
20+
bckCmd := &cobra.Command{
21+
Use: "backup",
22+
Short: "OpenCloud backup functionality",
23+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
2624
return configlog.ReturnError(parser.ParseConfig(cfg, true))
2725
},
28-
Action: func(_ *cli.Context) error {
29-
fmt.Println("Read the docs")
30-
return nil
31-
},
3226
}
27+
bckCmd.AddCommand(ConsistencyCommand(cfg))
28+
return bckCmd
3329
}
3430

3531
// ConsistencyCommand is the entrypoint for the consistency Command
36-
func ConsistencyCommand(cfg *config.Config) *cli.Command {
37-
return &cli.Command{
38-
Name: "consistency",
39-
Usage: "check backup consistency",
40-
Flags: []cli.Flag{
41-
&cli.StringFlag{
42-
Name: "basepath",
43-
Aliases: []string{"p"},
44-
Usage: "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)",
45-
Required: true,
46-
},
47-
&cli.StringFlag{
48-
Name: "blobstore",
49-
Aliases: []string{"b"},
50-
Usage: "the blobstore type. Can be (none, decomposed, decomposeds3). Default decomposed",
51-
Value: "decomposed",
52-
},
53-
&cli.BoolFlag{
54-
Name: "fail",
55-
Usage: "exit with non-zero status if consistency check fails",
56-
},
57-
},
58-
Action: func(c *cli.Context) error {
59-
basePath := c.String("basepath")
60-
if basePath == "" {
61-
fmt.Println("basepath is required")
62-
return cli.ShowCommandHelp(c, "consistency")
63-
}
64-
32+
func ConsistencyCommand(cfg *config.Config) *cobra.Command {
33+
consCmd := &cobra.Command{
34+
Use: "consistency",
35+
Short: "check backup consistency",
36+
RunE: func(cmd *cobra.Command, args []string) error {
6537
var (
6638
bs backup.ListBlobstore
6739
err error
6840
)
69-
switch c.String("blobstore") {
41+
basePath, _ := cmd.Flags().GetString("basepath")
42+
blobstoreFlag, _ := cmd.Flags().GetString("blobstore")
43+
switch blobstoreFlag {
7044
case "decomposeds3":
7145
bs, err = decomposeds3bs.New(
7246
cfg.StorageUsers.Drivers.DecomposedS3.Endpoint,
@@ -87,14 +61,20 @@ func ConsistencyCommand(cfg *config.Config) *cli.Command {
8761
fmt.Println(err)
8862
return err
8963
}
90-
if err := backup.CheckProviderConsistency(basePath, bs, c.Bool("fail")); err != nil {
64+
fail, _ := cmd.Flags().GetBool("fail")
65+
if err := backup.CheckProviderConsistency(basePath, bs, fail); err != nil {
9166
fmt.Println(err)
9267
return err
9368
}
9469

9570
return nil
9671
},
9772
}
73+
consCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)")
74+
_ = consCmd.MarkFlagRequired("basepath")
75+
consCmd.Flags().StringP("blobstore", "b", "decomposed", "the blobstore type. Can be (none, decomposed, decomposeds3). Default decomposed")
76+
consCmd.Flags().Bool("fail", false, "exit with non-zero status if consistency check fails")
77+
return consCmd
9878
}
9979

10080
func init() {

0 commit comments

Comments
 (0)