99 "syscall"
1010
1111 "github.com/daptin/daptin-cli/client"
12+ "github.com/daptin/daptin-cli/render"
1213 daptinClient "github.com/daptin/daptin-go-client"
1314 "github.com/urfave/cli/v2"
1415 "golang.org/x/term"
@@ -48,7 +49,7 @@ func executeCommand(appCtx *AppContext) *cli.Command {
4849 slog .Debug ("interactive mode enabled, fetching schema" )
4950 schema , schemaErr := fetchActionSchemaFromServer (appCtx , entityName , actionName )
5051 if schemaErr == nil {
51- prompts := MissingFields (schema , attrs )
52+ prompts := MissingFields (schema . InFields , attrs )
5253 filled , err := promptUser (prompts )
5354 if err != nil {
5455 return err
@@ -70,6 +71,9 @@ func executeCommand(appCtx *AppContext) *cli.Command {
7071
7172 // Pure: compute effects from responses
7273 effects := ProcessResponses (responses )
74+ if len (effects ) == 0 {
75+ effects = append (effects , BuildActionSuccessEffect (entityName , actionName , c .String ("reference-id" )))
76+ }
7377
7478 // IO boundary: apply effects
7579 return applyEffects (effects , appCtx )
@@ -103,50 +107,66 @@ func applyEffects(effects []ResponseEffect, appCtx *AppContext) error {
103107 if err := appCtx .Renderer .RenderObject (e .Data ); err != nil {
104108 return err
105109 }
110+ case "success" :
111+ if appCtx .Quiet {
112+ continue
113+ }
114+ if _ , ok := appCtx .Renderer .(* render.JsonRenderer ); ok {
115+ if err := appCtx .Renderer .RenderObject (e .Data ); err != nil {
116+ return err
117+ }
118+ continue
119+ }
120+ fmt .Fprintln (os .Stdout , e .Message )
106121 }
107122 }
108123 return nil
109124}
110125
111126// fetchActionSchemaFromServer fetches InFields for an action via the API.
112127// IO boundary: makes HTTP calls, then delegates to pure functions.
113- func fetchActionSchemaFromServer (appCtx * AppContext , entityName , actionName string ) ([] map [ string ] interface {} , error ) {
128+ func fetchActionSchemaFromServer (appCtx * AppContext , entityName , actionName string ) (ActionSchema , error ) {
114129 slog .Debug ("fetching action schema" , "entity" , entityName , "action" , actionName )
115130 worlds , err := appCtx .Client .FindAll ("world" , daptinClient.DaptinQueryParameters {
116131 "page[size]" : 500 ,
117132 })
118133 if err != nil {
119- return nil , err
134+ return ActionSchema {} , err
120135 }
121136
122137 worldAttrs := client .MapArray (worlds , "attributes" )
123138 worldRefId := FindWorldRefId (worldAttrs , entityName )
124139 if worldRefId == "" {
125- return nil , fmt .Errorf ("entity %q not found" , entityName )
140+ return ActionSchema {} , fmt .Errorf ("entity %q not found" , entityName )
126141 }
127142
128143 actions , err := appCtx .Client .FindAll ("action" , daptinClient.DaptinQueryParameters {
129144 "page[size]" : 500 ,
130145 })
131146 if err != nil {
132- return nil , err
147+ return ActionSchema {} , err
133148 }
134149
135150 actionAttrs := client .MapArray (actions , "attributes" )
136- actionRefId := FindActionRefId (actionAttrs , worldRefId , actionName )
137- if actionRefId == "" {
138- return nil , fmt .Errorf ("action %q not found on %q" , actionName , entityName )
151+ schema := FindActionMetadata (actionAttrs , worldRefId , entityName , actionName )
152+ if schema . ReferenceID == "" {
153+ return ActionSchema {} , fmt .Errorf ("action %q not found on %q" , actionName , entityName )
139154 }
140155
141156 // Execute get_action_schema to retrieve the schema (base64 encoded)
142157 responses , err := appCtx .Client .Execute ("get_action_schema" , "action" , daptinClient.JsonApiObject {
143- "action_id" : actionRefId ,
158+ "action_id" : schema . ReferenceID ,
144159 })
145160 if err != nil {
146- return nil , err
161+ return ActionSchema {} , err
147162 }
148163
149- return DecodeActionSchemaResponse (responses )
164+ inFields , err := DecodeActionSchemaResponse (responses )
165+ if err != nil {
166+ return ActionSchema {}, err
167+ }
168+ schema .InFields = inFields
169+ return schema , nil
150170}
151171
152172// promptUser performs IO to collect values for missing fields.
0 commit comments