Skip to content

Commit 712b149

Browse files
committed
Update urfave/cli to v3
1 parent ece3a9b commit 712b149

File tree

7 files changed

+72
-84
lines changed

7 files changed

+72
-84
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
nextmn-srv6
22
srv6
3-
!bash-completion/completions/nextmn-srv6
43
env

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright © Louis Royer and the NextMN Contributors
3+
Copyright Louis Royer and the NextMN Contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ IPROUTE2_RTTABLES_D = /etc/iproute2/rt_tables.d
99
RM = rm -f
1010
INSTALL = install -D
1111
MAKE = make --no-print-directory
12+
MKDIRP = mkdir -p
1213

1314
.PHONY: install uninstall update build clean default
1415
default: build
@@ -23,10 +24,11 @@ install:
2324
$(INSTALL) srv6 $(DESTDIR)$(bindir)/srv6
2425
$(INSTALL) etc/iproute2/rt_protos.d/nextmn.conf $(DESTDIR)$(IPROUTE2_RTPROTOS_D)/nextmn.conf
2526
$(INSTALL) etc/iproute2/rt_tables.d/nextmn.conf $(DESTDIR)$(IPROUTE2_RTTABLES_D)/nextmn.conf
26-
$(INSTALL) bash-completion/completions/srv6 $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6
27+
$(MKDIRP) $(DESTDIR)$(BASHCOMPLETIONSDIR)
28+
$(DESTDIR)$(bindir)/srv6 completion bash > $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6
2729
@echo "================================="
2830
@echo ">> Now run the following command:"
29-
@echo -e "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6"
31+
@echo "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6"
3032
@echo "================================="
3133
uninstall:
3234
$(RM) $(DESTDIR)$(bindir)/srv6

bash-completion/completions/srv6

Lines changed: 0 additions & 21 deletions
This file was deleted.

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ module github.com/nextmn/srv6
33
go 1.25.5
44

55
require (
6-
github.com/adrg/xdg v0.5.3
76
github.com/gin-gonic/gin v1.11.0
87
github.com/gofrs/uuid/v5 v5.4.0
98
github.com/google/gopacket v1.1.19
109
github.com/lib/pq v1.10.9
10+
github.com/nextmn/cli-xdg v0.0.1
1111
github.com/nextmn/gopacket-gtp v0.0.8
1212
github.com/nextmn/gopacket-srv6 v0.0.8
1313
github.com/nextmn/json-api v0.1.0
1414
github.com/nextmn/logrus-formatter v0.0.2
1515
github.com/nextmn/rfc9433 v0.0.3
1616
github.com/sirupsen/logrus v1.9.3
1717
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
18-
github.com/urfave/cli/v2 v2.27.7
18+
github.com/urfave/cli/v3 v3.6.1
1919
gopkg.in/yaml.v3 v3.0.1
2020
)
2121

2222
require (
23+
github.com/adrg/xdg v0.5.3 // indirect
2324
github.com/bytedance/gopkg v0.1.3 // indirect
2425
github.com/bytedance/sonic v1.14.2 // indirect
2526
github.com/bytedance/sonic/loader v0.4.0 // indirect
2627
github.com/cloudwego/base64x v0.1.6 // indirect
27-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
2828
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
2929
github.com/gin-contrib/sse v1.1.0 // indirect
3030
github.com/go-playground/locales v0.14.1 // indirect
@@ -42,10 +42,8 @@ require (
4242
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
4343
github.com/quic-go/qpack v0.6.0 // indirect
4444
github.com/quic-go/quic-go v0.58.0 // indirect
45-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
4645
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4746
github.com/ugorji/go/codec v1.3.1 // indirect
48-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
4947
go.uber.org/mock v0.6.0 // indirect
5048
golang.org/x/arch v0.23.0 // indirect
5149
golang.org/x/crypto v0.46.0 // indirect

go.sum

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ github.com/bytedance/sonic/loader v0.4.0 h1:olZ7lEqcxtZygCK9EKYKADnpQoYkRQxaeY2N
88
github.com/bytedance/sonic/loader v0.4.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
99
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
1010
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
11-
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
12-
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
1311
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1412
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1513
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -58,6 +56,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
5856
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
5957
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
6058
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
59+
github.com/nextmn/cli-xdg v0.0.1 h1:IboSpc2dPINT9/ErwW+9rVFmckaMp7s/oEMx5+kDgL4=
60+
github.com/nextmn/cli-xdg v0.0.1/go.mod h1:Uzay2Eepw4hfwNVHa6KWnb2mj/Cxiyh4iFllbzkavdc=
6161
github.com/nextmn/gopacket-gtp v0.0.8 h1:NF3GRPSdDjmoTeyN584NwbJJJ3tHwPZysZE2ma/fYvY=
6262
github.com/nextmn/gopacket-gtp v0.0.8/go.mod h1:94jLjLU04IOVTKBXUP09MXZCgmlizqmflU2ion1ht6E=
6363
github.com/nextmn/gopacket-srv6 v0.0.8 h1:oP4wuJ7dOiV/gWmX3zoFcdp2dKdSWLUaxH2fJ3TYAwA=
@@ -78,8 +78,6 @@ github.com/quic-go/quic-go v0.58.0 h1:ggY2pvZaVdB9EyojxL1p+5mptkuHyX5MOSv4dgWF4U
7878
github.com/quic-go/quic-go v0.58.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
7979
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
8080
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
81-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
82-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
8381
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
8482
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
8583
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
@@ -100,10 +98,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
10098
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
10199
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
102100
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
103-
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
104-
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
105-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
106-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
101+
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
102+
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
107103
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
108104
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
109105
golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg=

main.go

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,100 @@ import (
99
"context"
1010
"os"
1111
"os/signal"
12+
"runtime/debug"
1213
"syscall"
1314

15+
"github.com/nextmn/cli-xdg"
1416
"github.com/nextmn/json-api/healthcheck"
1517
"github.com/nextmn/logrus-formatter/logger"
1618

1719
"github.com/nextmn/srv6/internal/app"
1820
"github.com/nextmn/srv6/internal/config"
1921

20-
"github.com/adrg/xdg"
2122
"github.com/sirupsen/logrus"
22-
"github.com/urfave/cli/v2"
23+
"github.com/urfave/cli/v3"
2324
)
2425

2526
func main() {
26-
logger.Init("NextMN-Srv6")
27+
logger.Init("NextMN-SRv6")
2728
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
2829
defer cancel()
29-
app := &cli.App{
30-
Name: "NextMN-SRv6",
31-
Usage: "Experimental implementation of SRv6 SIDs for MUP",
32-
EnableBashCompletion: true,
33-
Authors: []*cli.Author{
34-
{Name: "Louis Royer"},
30+
version := "Unknown version"
31+
if info, ok := debug.ReadBuildInfo(); ok {
32+
version = info.Main.Version
33+
}
34+
app := &cli.Command{
35+
Name: "srv6",
36+
Usage: "NextMN-SRv6 - Experimental implementation of SRv6 SIDs for MUP",
37+
EnableShellCompletion: true,
38+
Authors: []any{
39+
"Louis Royer",
3540
},
36-
HideHelpCommand: true,
41+
Version: version,
3742
Flags: []cli.Flag{
3843
&cli.StringFlag{
39-
Name: "config",
40-
Aliases: []string{"c"},
41-
Usage: "Load configuration from `FILE`",
42-
Required: false,
44+
Name: "config",
45+
TakesFile: true,
46+
Aliases: []string{"c"},
47+
Usage: "load configuration from `FILE`",
48+
// XXX: https://github.com/urfave/cli/issues/2244
49+
// Required: true,
4350
DefaultText: "${XDG_CONFIG_DIRS}/nextmn-srv6/config.yaml",
44-
EnvVars: []string{"CONFIG_FILE"},
51+
Sources: cli.NewValueSourceChain(
52+
cli.EnvVar("CONFIG_FILE"),
53+
clixdg.ConfigFile("nextmn-srv6/config.yaml"),
54+
),
4555
},
4656
},
47-
Before: func(ctx *cli.Context) error {
48-
if ctx.Path("config") == "" {
49-
if xdgPath, err := xdg.SearchConfigFile("nextmn-srv6/config.yaml"); err != nil {
50-
cli.ShowAppHelp(ctx)
51-
logrus.WithError(err).Fatal("No configuration file defined")
52-
} else {
53-
ctx.Set("config", xdgPath)
54-
}
55-
}
56-
return nil
57-
},
58-
Action: func(ctx *cli.Context) error {
59-
conf, err := config.ParseConf(ctx.Path("config"))
60-
if err != nil {
61-
logrus.WithContext(ctx.Context).WithError(err).Fatal("Error loading config, exiting…")
62-
}
63-
if conf.Logger != nil {
64-
logrus.SetLevel(conf.Logger.Level)
65-
}
66-
if err := app.NewSetup(conf).Run(ctx.Context); err != nil {
67-
logrus.WithError(err).Fatal("Error while running, exiting…")
68-
}
69-
return nil
70-
},
57+
DefaultCommand: "run",
7158
Commands: []*cli.Command{
59+
{
60+
Name: "run",
61+
Usage: "Runs the SRv6 node",
62+
Action: func(ctx context.Context, cmd *cli.Command) error {
63+
// XXX: https://github.com/urfave/cli/issues/2244
64+
if cmd.String("config") == "" {
65+
logrus.Fatal("Required flag \"config\" not set")
66+
}
67+
68+
conf, err := config.ParseConf(cmd.String("config"))
69+
if err != nil {
70+
logrus.WithContext(ctx).WithError(err).Fatal("Error loading config, exiting…")
71+
}
72+
if conf.Logger != nil {
73+
logrus.SetLevel(conf.Logger.Level)
74+
}
75+
if err := app.NewSetup(conf).Run(ctx); err != nil {
76+
logrus.WithError(err).Fatal("Error while running, exiting…")
77+
}
78+
return nil
79+
},
80+
},
7281
{
7382
Name: "healthcheck",
74-
Usage: "check status of the node",
75-
Action: func(ctx *cli.Context) error {
76-
conf, err := config.ParseConf(ctx.Path("config"))
83+
Usage: "Checks status of the node",
84+
Action: func(ctx context.Context, cmd *cli.Command) error {
85+
// XXX: https://github.com/urfave/cli/issues/2244
86+
if cmd.String("config") == "" {
87+
logrus.Fatal("Required flag \"config\" not set")
88+
}
89+
90+
conf, err := config.ParseConf(cmd.String("config"))
7791
if err != nil {
78-
logrus.WithContext(ctx.Context).WithError(err).Fatal("Error loading config, exiting…")
92+
logrus.WithContext(ctx).WithError(err).Fatal("Error loading config, exiting…")
7993
}
8094
if conf.Logger != nil {
8195
logrus.SetLevel(conf.Logger.Level)
8296
}
83-
if err := healthcheck.NewHealthcheck(*conf.Control.Uri.JoinPath("status"), "go-github-nextmn-srv6").Run(ctx.Context); err != nil {
97+
if err := healthcheck.NewHealthcheck(*conf.Control.Uri.JoinPath("status"), "go-github-nextmn-srv6").Run(ctx); err != nil {
8498
os.Exit(1)
8599
}
86100
return nil
87101
},
88102
},
89103
},
90104
}
91-
if err := app.RunContext(ctx, os.Args); err != nil {
92-
logrus.Fatal(err)
105+
if err := app.Run(ctx, os.Args); err != nil {
106+
logrus.WithError(err).Fatal("Fatal error while running the application")
93107
}
94108
}

0 commit comments

Comments
 (0)