package spec import ( "os" 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/pkg/client" "github.com/pkg/errors" "github.com/urfave/cli/v2" "gitlab.com/wpetit/goweb/cli/format" ) func GetCommand() *cli.Command { return &cli.Command{ Name: "get", Usage: "Get agent specification", Flags: agentFlag.WithAgentFlags( &cli.StringFlag{ Name: "spec-name", Usage: "use `NAME` as specification's name", }, &cli.StringFlag{ Name: "spec-version", Usage: "use `VERSION` as specification's version", Value: "0.0.0", }, ), Action: func(ctx *cli.Context) error { baseFlags := clientFlag.GetBaseFlags(ctx) agentID, err := agentFlag.AssertAgentID(ctx) if err != nil { return errors.WithStack(err) } token, err := clientFlag.GetToken(baseFlags) if err != nil { return errors.WithStack(apierr.Wrap(err)) } specDefName, err := assertSpecDefName(ctx) if err != nil { return errors.WithStack(err) } specDefVersion, err := assertSpecDefVersion(ctx) if err != nil { return errors.WithStack(err) } client := client.New(baseFlags.ServerURL, client.WithToken(token)) spec, err := client.GetAgentSpec(ctx.Context, agentID, specDefName, specDefVersion) if err != nil { return errors.WithStack(apierr.Wrap(err)) } hints := specHints(baseFlags.OutputMode) if err := format.Write(baseFlags.Format, os.Stdout, hints, spec); err != nil { return errors.WithStack(err) } return nil }, } }