@@ -5,12 +5,11 @@ import (
55 "context"
66 "encoding/json"
77 "fmt"
8+ "io"
89 "strings"
910
1011 "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"
1413)
1514
1615const updateABCWorkflowInstanceVariablesMutation = `mutation UpdateAgenticWorkflowInstanceVariables(
@@ -22,74 +21,6 @@ const updateABCWorkflowInstanceVariablesMutation = `mutation UpdateAgenticWorkfl
2221 }
2322}`
2423
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-
32- Examples:
33-
34- Set a string variable on a workflow instance:
35-
36- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== prompt="tighten the review criteria"
37-
38- Set multiple variables in one request:
39-
40- $ src abc variables set QWdlbnRpY1dvcmtmbG93SW5zdGFuY2U6MQ== --var prompt="tighten the review criteria" --var checkpoints='[1,2,3]'
41-
42- Set a structured JSON value:
43-
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 {
56- return cmderrors .Usage ("must provide a workflow instance ID" )
57- }
58-
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
90- },
91- })
92-
9324type abcVariableArgs []string
9425
9526func (a * abcVariableArgs ) String () string {
@@ -142,6 +73,37 @@ func parseABCVariable(raw string) (abcVariable, error) {
14273 return abcVariable {Key : name , Value : value }, nil
14374}
14475
76+ func runABCVariablesSet (ctx context.Context , client api.Client , instanceID string , positional []string , flagged abcVariableArgs , output io.Writer , getCurl bool ) error {
77+ variables , err := parseABCVariables (positional , flagged )
78+ if err != nil {
79+ return err
80+ }
81+
82+ graphqlVariables := make ([]map [string ]string , 0 , len (variables ))
83+ for _ , variable := range variables {
84+ graphqlVariables = append (graphqlVariables , map [string ]string {
85+ "key" : variable .Key ,
86+ "value" : variable .Value ,
87+ })
88+ }
89+
90+ if err := updateABCWorkflowInstanceVariables (ctx , client , instanceID , graphqlVariables ); err != nil {
91+ return err
92+ }
93+
94+ if getCurl {
95+ return nil
96+ }
97+
98+ if len (variables ) == 1 {
99+ _ , err = fmt .Fprintf (output , "Set variable %q on workflow instance %q.\n " , variables [0 ].Key , instanceID )
100+ return err
101+ }
102+
103+ _ , err = fmt .Fprintf (output , "Updated %d variables on workflow instance %q.\n " , len (variables ), instanceID )
104+ return err
105+ }
106+
145107func updateABCWorkflowInstanceVariables (ctx context.Context , client api.Client , instanceID string , variables []map [string ]string ) error {
146108 var result struct {
147109 UpdateAgenticWorkflowInstanceVariables struct {
0 commit comments