package agent import ( "os" agentFlag "forge.cadoles.com/Cadoles/emissary/internal/command/api/agent/flag" "forge.cadoles.com/Cadoles/emissary/internal/command/api/apierr" clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/api/flag" "forge.cadoles.com/Cadoles/emissary/pkg/client" "github.com/pkg/errors" "github.com/urfave/cli/v2" "gitlab.com/wpetit/goweb/cli/format" ) func UpdateCommand() *cli.Command { return &cli.Command{ Name: "update", Usage: "Updata agent", Flags: agentFlag.WithAgentFlags( &cli.IntFlag{ Name: "status", Usage: "Set `STATUS` to selected agent", Value: -1, }, &cli.StringFlag{ Name: "label", Usage: "Set `LABEL` to selected agent", Value: "", }, ), Action: func(ctx *cli.Context) error { baseFlags := clientFlag.GetBaseFlags(ctx) token, err := clientFlag.GetToken(baseFlags) if err != nil { return errors.WithStack(apierr.Wrap(err)) } agentID, err := agentFlag.AssertAgentID(ctx) if err != nil { return errors.WithStack(err) } options := make([]client.UpdateAgentOptionFunc, 0) status := ctx.Int("status") if status != -1 { options = append(options, client.WithAgentStatus(status)) } label := ctx.String("label") if label != "" { options = append(options, client.WithAgentLabel(label)) } client := client.New(baseFlags.ServerURL, client.WithToken(token)) agent, err := client.UpdateAgent(ctx.Context, agentID, options...) if err != nil { return errors.WithStack(apierr.Wrap(err)) } hints := agentHints(baseFlags.OutputMode) if err := format.Write(baseFlags.Format, os.Stdout, hints, agent); err != nil { return errors.WithStack(err) } return nil }, } }