Skip to content

Commit abb5fdc

Browse files
authored
Migrate codebase to use cli/v3 (#375)
Signed-off-by: Arrobo, Gabriel <gabriel.arrobo@intel.com>
1 parent f03ec73 commit abb5fdc

6 files changed

Lines changed: 38 additions & 45 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.7-dev
1+
1.8.7

backend/factory/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
utilLogger "github.com/omec-project/util/logger"
2020
"github.com/omec-project/webconsole/backend/logger"
21-
"github.com/urfave/cli"
21+
"github.com/urfave/cli/v3"
2222
"go.uber.org/zap"
2323
"go.uber.org/zap/zapcore"
2424
"gopkg.in/yaml.v2"
@@ -120,7 +120,7 @@ func SetLogLevelsFromConfig(cfg *Config) {
120120

121121
func GetCliFlags() []cli.Flag {
122122
return []cli.Flag{
123-
cli.StringFlag{
123+
&cli.StringFlag{
124124
Name: "cfg",
125125
Usage: "Path to configuration file",
126126
},

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/swaggo/files v1.0.1
1515
github.com/swaggo/gin-swagger v1.6.0
1616
github.com/swaggo/swag v1.16.4
17-
github.com/urfave/cli v1.22.17
17+
github.com/urfave/cli/v3 v3.3.8
1818
go.mongodb.org/mongo-driver v1.17.4
1919
go.uber.org/zap v1.27.0
2020
golang.org/x/crypto v0.39.0
@@ -31,7 +31,6 @@ require (
3131
github.com/bytedance/sonic/loader v0.2.4 // indirect
3232
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3333
github.com/cloudwego/base64x v0.1.5 // indirect
34-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
3534
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
3635
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
3736
github.com/gin-contrib/sse v1.1.0 // indirect
@@ -60,7 +59,6 @@ require (
6059
github.com/prometheus/client_model v0.6.2 // indirect
6160
github.com/prometheus/common v0.64.0 // indirect
6261
github.com/prometheus/procfs v0.16.1 // indirect
63-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
6462
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
6563
github.com/ugorji/go/codec v1.2.14 // indirect
6664
github.com/xdg-go/pbkdf2 v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
21
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
32
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
43
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
@@ -15,8 +14,6 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
1514
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
1615
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
1716
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
18-
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
19-
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2017
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2118
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2219
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -120,18 +117,14 @@ github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzM
120117
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
121118
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
122119
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
123-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
124-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
125120
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
126121
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
127122
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
128-
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
129123
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
130124
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
131125
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
132126
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
133127
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
134-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
135128
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
136129
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
137130
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
@@ -144,8 +137,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
144137
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
145138
github.com/ugorji/go/codec v1.2.14 h1:yOQvXCBc3Ij46LRkRoh4Yd5qK6LVOgi0bYOXfb7ifjw=
146139
github.com/ugorji/go/codec v1.2.14/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
147-
github.com/urfave/cli v1.22.17 h1:SYzXoiPfQjHBbkYxbew5prZHS1TOLT3ierW8SYLqtVQ=
148-
github.com/urfave/cli v1.22.17/go.mod h1:b0ht0aqgH/6pBYzzxURyrM4xXNgsoT/n2ZzwQiEhNVo=
140+
github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E=
141+
github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
149142
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
150143
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
151144
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=

server.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/omec-project/webconsole/backend/nfconfig"
1818
"github.com/omec-project/webconsole/backend/webui_service"
1919
"github.com/omec-project/webconsole/dbadapter"
20-
"github.com/urfave/cli"
20+
"github.com/urfave/cli/v3"
2121
)
2222

2323
var (
@@ -27,41 +27,43 @@ var (
2727
)
2828

2929
func main() {
30-
app := cli.NewApp()
30+
app := &cli.Command{}
3131
app.Name = "webui"
3232
logger.AppLog.Infoln(app.Name)
3333
app.Usage = "Web UI"
3434
app.UsageText = "webconsole -cfg <webui_config_file.yaml>"
3535
app.Flags = factory.GetCliFlags()
36-
app.Action = func(c *cli.Context) error {
37-
cfgPath := c.String("cfg")
38-
if cfgPath == "" {
39-
return fmt.Errorf("required flag cfg not set")
40-
}
41-
42-
absPath, err := filepath.Abs(cfgPath)
43-
if err != nil {
44-
return fmt.Errorf("failed to resolve config path: %w", err)
45-
}
46-
47-
if err := factory.InitConfigFactory(absPath); err != nil {
48-
return fmt.Errorf("failed to init config: %w", err)
49-
}
50-
51-
config := factory.WebUIConfig
52-
if config == nil {
53-
return fmt.Errorf("configuration not properly initialized")
54-
}
55-
factory.SetLogLevelsFromConfig(config)
56-
57-
return startApplication(config)
58-
}
36+
app.Action = action
5937

60-
if err := app.Run(os.Args); err != nil {
38+
if err := app.Run(context.Background(), os.Args); err != nil {
6139
logger.AppLog.Fatalf("error args: %v", err)
6240
}
6341
}
6442

43+
func action(ctx context.Context, c *cli.Command) error {
44+
cfgPath := c.String("cfg")
45+
if cfgPath == "" {
46+
return fmt.Errorf("required flag cfg not set")
47+
}
48+
49+
absPath, err := filepath.Abs(cfgPath)
50+
if err != nil {
51+
return fmt.Errorf("failed to resolve config path: %w", err)
52+
}
53+
54+
if err := factory.InitConfigFactory(absPath); err != nil {
55+
return fmt.Errorf("failed to init config: %w", err)
56+
}
57+
58+
config := factory.WebUIConfig
59+
if config == nil {
60+
return fmt.Errorf("configuration not properly initialized")
61+
}
62+
factory.SetLogLevelsFromConfig(config)
63+
64+
return startApplication(config)
65+
}
66+
6567
func startApplication(config *factory.Config) error {
6668
if config == nil || config.Configuration == nil {
6769
return fmt.Errorf("configuration section is nil")

server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/omec-project/webconsole/backend/factory"
1515
"github.com/omec-project/webconsole/backend/nfconfig"
1616
"github.com/omec-project/webconsole/backend/webui_service"
17-
"github.com/urfave/cli"
17+
"github.com/urfave/cli/v3"
1818
)
1919

2020
type mockWebUI struct {
@@ -115,19 +115,19 @@ func TestMainValidateCLIFlags(t *testing.T) {
115115

116116
for _, tt := range tests {
117117
t.Run(tt.name, func(t *testing.T) {
118-
app := cli.NewApp()
118+
app := &cli.Command{}
119119
app.Name = "webui"
120120
app.Usage = "Web UI"
121121
app.UsageText = "webconsole -cfg <webui_config_file.yaml>"
122122
app.Flags = factory.GetCliFlags()
123-
app.Action = func(c *cli.Context) error {
123+
app.Action = func(ctx context.Context, c *cli.Command) error {
124124
cfg := c.String("cfg")
125125
if cfg == "" {
126126
return fmt.Errorf("required flag cfg not set")
127127
}
128128
return nil
129129
}
130-
err := app.Run(tt.args)
130+
err := app.Run(context.Background(), tt.args)
131131

132132
if tt.expectError && err == nil {
133133
t.Error("expected error but got none")

0 commit comments

Comments
 (0)