11package main
22
33import (
4+ "context"
45 "fmt"
56 "log/slog"
67 "maps"
@@ -9,7 +10,7 @@ import (
910 "strings"
1011
1112 "github.com/lmittmann/tint"
12- cli "github.com/urfave/cli/v2 "
13+ cli "github.com/urfave/cli/v3 "
1314 "github.com/willabides/actionslog"
1415 "github.com/willabides/actionslog/human"
1516 "golang.org/x/term"
@@ -69,35 +70,43 @@ func main() {
6970 )
7071 }
7172
72- app := cli .NewApp ()
73+ app := cli.Command {}
7374 app .Name = "Runs the Argo CLI"
7475
75- app .Action = func (c * cli.Context ) error { return run (c , & lv , logger ) }
76+ app .Action = func (ctx context. Context , c * cli.Command ) error { return run (ctx , c , & lv , logger ) }
7677
7778 app .Flags = []cli.Flag {
7879 & cli.BoolFlag {
79- Name : flagAddCILabels ,
80- EnvVars : []string {"ADD_CI_LABELS" },
81- Value : false ,
82- Usage : "If true, the `--labels` argument will be added with values from the environment. This is forced for the `submit` command" ,
80+ Name : flagAddCILabels ,
81+ Sources : cli .NewValueSourceChain (
82+ cli .EnvVar ("ADD_CI_LABELS" ),
83+ ),
84+ Value : false ,
85+ Usage : "If true, the `--labels` argument will be added with values from the environment. This is forced for the `submit` command" ,
8386 },
8487 & cli.StringFlag {
85- Name : flagNamespace ,
86- EnvVars : []string {"ARGO_NAMESPACE" },
88+ Name : flagNamespace ,
89+ Sources : cli .NewValueSourceChain (
90+ cli .EnvVar ("ARGO_NAMESPACE" ),
91+ ),
8792 Required : true ,
8893 },
8994 & cli.StringFlag {
90- Name : flagArgoToken ,
91- EnvVars : []string {"ARGO_TOKEN" },
95+ Name : flagArgoToken ,
96+ Sources : cli .NewValueSourceChain (
97+ cli .EnvVar ("ARGO_TOKEN" ),
98+ ),
9299 Usage : "The Argo token to use for authentication" ,
93100 Required : true ,
94101 },
95102 & cli.StringFlag {
96- Name : flagLogLevel ,
97- EnvVars : []string {"LOG_LEVEL" },
98- Usage : "Which log level to use" ,
99- Value : "info" ,
100- Action : func (c * cli.Context , level string ) error {
103+ Name : flagLogLevel ,
104+ Sources : cli .NewValueSourceChain (
105+ cli .EnvVar ("LOG_LEVEL" ),
106+ ),
107+ Usage : "Which log level to use" ,
108+ Value : "info" ,
109+ Action : func (ctx context.Context , c * cli.Command , level string ) error {
101110 level = strings .ToLower (level )
102111
103112 lvl , err := parseLogLevel (level )
@@ -111,10 +120,12 @@ func main() {
111120 },
112121 },
113122 & cli.StringFlag {
114- Name : flagInstance ,
115- EnvVars : []string {"INSTANCE" },
116- Value : "ops" ,
117- Action : func (c * cli.Context , instance string ) error {
123+ Name : flagInstance ,
124+ Sources : cli .NewValueSourceChain (
125+ cli .EnvVar ("INSTANCE" ),
126+ ),
127+ Value : "ops" ,
128+ Action : func (ctx context.Context , c * cli.Command , instance string ) error {
118129 // Validate it is a known instance
119130 instances := slices .Collect (maps .Keys (instanceToHost ))
120131 if ! slices .Contains (instances , instance ) {
@@ -129,16 +140,20 @@ func main() {
129140 Usage : "Parameters to pass to the workflow template. Given as `key=value`. Specify multiple times for multiple parameters" ,
130141 },
131142 & cli.UintFlag {
132- Name : flagRetries ,
133- EnvVars : []string {"RETRIES" },
134- Value : 3 ,
135- Usage : "Number of retries to make if the command fails" ,
143+ Name : flagRetries ,
144+ Sources : cli .NewValueSourceChain (
145+ cli .EnvVar ("RETRIES" ),
146+ ),
147+ Value : 3 ,
148+ Usage : "Number of retries to make if the command fails" ,
136149 },
137150 & cli.StringFlag {
138- Name : flagWorkflowTemplate ,
139- EnvVars : []string {"WORKFLOW_TEMPLATE" },
140- Usage : "The workflow template to use" ,
141- Action : func (c * cli.Context , tpl string ) error {
151+ Name : flagWorkflowTemplate ,
152+ Sources : cli .NewValueSourceChain (
153+ cli .EnvVar ("WORKFLOW_TEMPLATE" ),
154+ ),
155+ Usage : "The workflow template to use" ,
156+ Action : func (ctx context.Context , c * cli.Command , tpl string ) error {
142157 // Required if command is `submit`
143158 if c .Args ().First () == "submit" && tpl == "" {
144159 return fmt .Errorf ("required flag: %s" , flagWorkflowTemplate )
@@ -148,13 +163,13 @@ func main() {
148163 },
149164 }
150165
151- if err := app .Run (os .Args ); err != nil {
166+ if err := app .Run (context . Background (), os .Args ); err != nil {
152167 logger .With ("error" , err ).Error ("failed to run" )
153168 os .Exit (1 )
154169 }
155170}
156171
157- func run (c * cli.Context , level * slog.LevelVar , logger * slog.Logger ) error {
172+ func run (ctx context. Context , c * cli.Command , level * slog.LevelVar , logger * slog.Logger ) error {
158173 addCILabels := c .Bool (flagAddCILabels )
159174 argoToken := c .String (flagArgoToken )
160175 command := c .Args ().First ()
0 commit comments