55 "context"
66 "encoding/json"
77 "fmt"
8+ "io"
89 "strings"
910
1011 "github.com/sourcegraph/src-cli/internal/api"
@@ -23,70 +24,42 @@ const updateABCWorkflowInstanceVariablesMutation = `mutation UpdateAgenticWorkfl
2324}`
2425
2526var 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> ...]
27+ Name : "set" ,
28+ UsageText : "src abc variables set [options] <workflow- instance-id> [<name>=<value> ...] " ,
29+ Usage : "Set variables on a workflow instance" ,
30+ Description : `
31+ Set workflow instance variables
3132
3233Examples:
3334
3435 Set a string variable on a workflow instance:
3536
36- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== prompt="tighten the review criteria"
37+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== prompt="tighten the review criteria"
3738
3839 Set multiple variables in one request:
3940
40- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== --var prompt="tighten the review criteria" --var checkpoints='[1,2,3]'
41+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== --var prompt="tighten the review criteria" --var checkpoints='[1,2,3]'
4142
4243 Set a structured JSON value:
4344
44- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== checkpoints='[1,2,3]'
45+ $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== checkpoints='[1,2,3]'
4546
46- Values are interpreted as JSON literals when valid. Otherwise they are sent as plain strings.` ,
47- DisableSliceFlagSeparator : true ,
47+ NOTE: Values are interpreted as JSON literals when valid. Otherwise they are sent as plain strings.
48+ ` ,
4849 Flags : clicompat .WithAPIFlags (
4950 & cli.StringSliceFlag {
5051 Name : "var" ,
5152 Usage : "Variable assignment in <name>=<value> form. Repeat to set multiple variables." ,
5253 },
5354 ),
54- Action : func (ctx context.Context , c * cli.Command ) error {
55- if c . NArg () == 0 {
55+ Action : func (ctx context.Context , cmd * cli.Command ) error {
56+ if ! cmd . Args (). Present () {
5657 return cmderrors .Usage ("must provide a workflow instance ID" )
5758 }
5859
59- instanceID := c .Args ().First ()
60- variables , err := parseABCVariables (c .Args ().Tail (), abcVariableArgs (c .StringSlice ("var" )))
61- if err != nil {
62- return err
63- }
64-
65- graphqlVariables := make ([]map [string ]string , 0 , len (variables ))
66- for _ , variable := range variables {
67- graphqlVariables = append (graphqlVariables , map [string ]string {
68- "key" : variable .Key ,
69- "value" : variable .Value ,
70- })
71- }
72-
73- apiFlags := clicompat .APIFlagsFromCmd (c )
74- client := cfg .apiClient (apiFlags , c .Writer )
75- if err := updateABCWorkflowInstanceVariables (ctx , client , instanceID , graphqlVariables ); err != nil {
76- return err
77- }
78-
79- if apiFlags .GetCurl () {
80- return nil
81- }
82-
83- if len (variables ) == 1 {
84- fmt .Fprintf (c .Writer , "Set variable %q on workflow instance %q.\n " , variables [0 ].Key , instanceID )
85- return nil
86- }
87-
88- fmt .Fprintf (c .Writer , "Updated %d variables on workflow instance %q.\n " , len (variables ), instanceID )
89- return nil
60+ instanceID := cmd .Args ().First ()
61+ client := cfg .apiClient (clicompat .APIFlagsFromCmd (cmd ), cmd .Writer )
62+ return runABCVariablesSet (ctx , client , instanceID , cmd .Args ().Tail (), abcVariableArgs (cmd .StringSlice ("var" )), cmd .Writer , cmd .Bool ("get-curl" ))
9063 },
9164})
9265
@@ -142,6 +115,37 @@ func parseABCVariable(raw string) (abcVariable, error) {
142115 return abcVariable {Key : name , Value : value }, nil
143116}
144117
118+ func runABCVariablesSet (ctx context.Context , client api.Client , instanceID string , positional []string , flagged abcVariableArgs , output io.Writer , getCurl bool ) error {
119+ variables , err := parseABCVariables (positional , flagged )
120+ if err != nil {
121+ return err
122+ }
123+
124+ graphqlVariables := make ([]map [string ]string , 0 , len (variables ))
125+ for _ , variable := range variables {
126+ graphqlVariables = append (graphqlVariables , map [string ]string {
127+ "key" : variable .Key ,
128+ "value" : variable .Value ,
129+ })
130+ }
131+
132+ if err := updateABCWorkflowInstanceVariables (ctx , client , instanceID , graphqlVariables ); err != nil {
133+ return err
134+ }
135+
136+ if getCurl {
137+ return nil
138+ }
139+
140+ if len (variables ) == 1 {
141+ _ , err = fmt .Fprintf (output , "Set variable %q on workflow instance %q.\n " , variables [0 ].Key , instanceID )
142+ return err
143+ }
144+
145+ _ , err = fmt .Fprintf (output , "Updated %d variables on workflow instance %q.\n " , len (variables ), instanceID )
146+ return err
147+ }
148+
145149func updateABCWorkflowInstanceVariables (ctx context.Context , client api.Client , instanceID string , variables []map [string ]string ) error {
146150 var result struct {
147151 UpdateAgenticWorkflowInstanceVariables struct {
0 commit comments