@@ -4,12 +4,13 @@ import (
44 "bytes"
55 "context"
66 "encoding/json"
7- "flag"
87 "fmt"
98 "strings"
109
1110 "github.com/sourcegraph/src-cli/internal/api"
11+ "github.com/sourcegraph/src-cli/internal/clicompat"
1212 "github.com/sourcegraph/src-cli/internal/cmderrors"
13+ "github.com/urfave/cli/v3"
1314)
1415
1516const updateABCWorkflowInstanceVariablesMutation = `mutation UpdateAgenticWorkflowInstanceVariables(
@@ -21,47 +22,42 @@ const updateABCWorkflowInstanceVariablesMutation = `mutation UpdateAgenticWorkfl
2122 }
2223}`
2324
24- func init () {
25- usage := `
25+ var abcVariablesSetCommand = clicompat .Wrap (& cli.Command {
26+ Name : "set" ,
27+ Usage : "set workflow instance variables" ,
28+ Description : `Usage:
29+
30+ src abc variables set [command options] <workflow-instance-id> [<name>=<value> ...]
31+
2632Examples:
2733
2834 Set a string variable on a workflow instance:
2935
30- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== prompt="tighten the review criteria"
36+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== prompt="tighten the review criteria"
3137
3238 Set multiple variables in one request:
3339
34- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== --var prompt="tighten the review criteria" --var checkpoints='[1,2,3]'
40+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== --var prompt="tighten the review criteria" --var checkpoints='[1,2,3]'
3541
3642 Set a structured JSON value:
3743
38- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== checkpoints='[1,2,3]'
39-
40- Values are interpreted as JSON literals when valid. Otherwise they are sent as plain strings.
41- `
42-
43- flagSet := flag .NewFlagSet ("set" , flag .ExitOnError )
44- var variableArgs abcVariableArgs
45- flagSet .Var (& variableArgs , "var" , "Variable assignment in <name>=<value> form. Repeat to set multiple variables." )
46- usageFunc := func () {
47- fmt .Fprintf (flag .CommandLine .Output (), "Usage of 'src abc variables %s':\n " , flagSet .Name ())
48- flagSet .PrintDefaults ()
49- fmt .Println (usage )
50- }
51- apiFlags := api .NewFlags (flagSet )
52-
53- handler := func (args []string ) error {
54- if len (args ) == 0 {
44+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== checkpoints='[1,2,3]'
45+
46+ Values are interpreted as JSON literals when valid. Otherwise they are sent as plain strings.` ,
47+ DisableSliceFlagSeparator : true ,
48+ Flags : clicompat .WithAPIFlags (
49+ & cli.StringSliceFlag {
50+ Name : "var" ,
51+ Usage : "Variable assignment in <name>=<value> form. Repeat to set multiple variables." ,
52+ },
53+ ),
54+ Action : func (ctx context.Context , c * cli.Command ) error {
55+ if c .NArg () == 0 {
5556 return cmderrors .Usage ("must provide a workflow instance ID" )
5657 }
5758
58- instanceID := args [0 ]
59- variableArgs = nil
60- if err := flagSet .Parse (args [1 :]); err != nil {
61- return err
62- }
63-
64- variables , err := parseABCVariables (flagSet .Args (), variableArgs )
59+ instanceID := c .Args ().First ()
60+ variables , err := parseABCVariables (c .Args ().Tail (), abcVariableArgs (c .StringSlice ("var" )))
6561 if err != nil {
6662 return err
6763 }
@@ -74,8 +70,9 @@ Values are interpreted as JSON literals when valid. Otherwise they are sent as p
7470 })
7571 }
7672
77- client := cfg .apiClient (apiFlags , flagSet .Output ())
78- if err := updateABCWorkflowInstanceVariables (context .Background (), client , instanceID , graphqlVariables ); err != nil {
73+ apiFlags := clicompat .APIFlagsFromCmd (c )
74+ client := cfg .apiClient (apiFlags , c .Writer )
75+ if err := updateABCWorkflowInstanceVariables (ctx , client , instanceID , graphqlVariables ); err != nil {
7976 return err
8077 }
8178
@@ -84,20 +81,14 @@ Values are interpreted as JSON literals when valid. Otherwise they are sent as p
8481 }
8582
8683 if len (variables ) == 1 {
87- fmt .Printf ( "Set variable %q on workflow instance %q.\n " , variables [0 ].Key , instanceID )
84+ fmt .Fprintf ( c . Writer , "Set variable %q on workflow instance %q.\n " , variables [0 ].Key , instanceID )
8885 return nil
8986 }
9087
91- fmt .Printf ( "Updated %d variables on workflow instance %q.\n " , len (variables ), instanceID )
88+ fmt .Fprintf ( c . Writer , "Updated %d variables on workflow instance %q.\n " , len (variables ), instanceID )
9289 return nil
93- }
94-
95- abcVariablesCommands = append (abcVariablesCommands , & command {
96- flagSet : flagSet ,
97- handler : handler ,
98- usageFunc : usageFunc ,
99- })
100- }
90+ },
91+ })
10192
10293type abcVariableArgs []string
10394
0 commit comments