package agent import ( "os" "forge.cadoles.com/Cadoles/emissary/internal/client" agentFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/agent/flag" "forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr" clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag" "forge.cadoles.com/Cadoles/emissary/internal/format" "github.com/pkg/errors" "github.com/urfave/cli/v2" ) 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, }, ), Action: func(ctx *cli.Context) error { baseFlags := clientFlag.GetBaseFlags(ctx) 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)) } client := client.New(baseFlags.ServerURL) 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 }, } }