func BuildWorkflowRunCommand()

in packages/cli/internal/pkg/cli/workflow_run.go [46:83]


func BuildWorkflowRunCommand() *cobra.Command {
	vars := runWorkflowVars{}
	cmd := &cobra.Command{
		Use:   "run workflow_name --context context_name",
		Short: "Run a workflow",
		Long: `run is for running the specified workflow in the specified context.
This command prints a run Id for the created workflow instance.
`,
		Example: `
Run the workflow named "example-workflow", against the "prod" context,
using input parameters contained in file "file:///Users/ec2-user/myproj/test-args.json"
/code $ agc workflow run example-workflow --context prod --args file:///Users/ec2-user/myproj/test-args.json`,
		Args: cobra.ExactArgs(1),
		RunE: runCmdE(func(cmd *cobra.Command, args []string) error {
			vars.WorkflowName = args[0]
			opts, err := newRunWorkflowOpts(vars)
			if err != nil {
				return clierror.New("workflow run", vars, err)
			}
			log.Info().Msgf("Running workflow. Workflow name: '%s', Arguments: '%s', Context: '%s'", opts.WorkflowName, opts.Arguments, opts.ContextName)
			if err := opts.Validate(); err != nil {
				return err
			}
			instanceId, err := opts.Execute()
			if err != nil {
				return clierror.New("workflow run", vars, err)
			}
			format.Default.Write(instanceId)
			return nil
		}),
		ValidArgsFunction: NewWorkflowAutoComplete().GetWorkflowAutoComplete(),
	}
	cmd.Flags().StringVarP(&vars.Arguments, argsFlag, argsFlagShort, "", argsFlagDescription)
	cmd.Flags().StringVarP(&vars.ContextName, contextFlag, contextFlagShort, "", contextFlagDescription)
	_ = cmd.MarkFlagRequired(contextFlag)
	_ = cmd.RegisterFlagCompletionFunc(contextFlag, NewContextAutoComplete().GetContextAutoComplete())
	return cmd
}