MCPcopy Create free account
hub / github.com/cli/cli / NewCmdRun

Function NewCmdRun

pkg/cmd/workflow/run/run.go:51–146  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*RunOptions) error)

Source from the content-addressed store, hash-verified

49}
50
51func NewCmdRun(f *cmdutil.Factory, runF func(*RunOptions) error) *cobra.Command {
52 opts := &RunOptions{
53 IO: f.IOStreams,
54 HttpClient: f.HttpClient,
55 Prompter: f.Prompter,
56 }
57
58 cmd := &cobra.Command{
59 Use: "run [<workflow-id> | <workflow-name>]",
60 Short: "Run a workflow by creating a workflow_dispatch event",
61 Long: heredoc.Docf(`
62 Create a %[1]sworkflow_dispatch%[1]s event for a given workflow.
63
64 This command will trigger GitHub Actions to run a given workflow file. The given workflow file must
65 support an %[1]son.workflow_dispatch%[1]s trigger in order to be run in this way.
66
67 If the workflow file supports inputs, they can be specified in a few ways:
68
69 - Interactively
70 - Via %[1]s-f/--raw-field%[1]s or %[1]s-F/--field%[1]s flags
71 - As JSON, via standard input
72
73 The created workflow run URL will be returned if available.
74 `, "`"),
75 Example: heredoc.Doc(`
76 # Have gh prompt you for what workflow you'd like to run and interactively collect inputs
77 $ gh workflow run
78
79 # Run the workflow file 'triage.yml' at the remote's default branch
80 $ gh workflow run triage.yml
81
82 # Run the workflow file 'triage.yml' at a specified ref
83 $ gh workflow run triage.yml --ref my-branch
84
85 # Run the workflow file 'triage.yml' with command line inputs
86 $ gh workflow run triage.yml -f name=scully -f greeting=hello
87
88 # Run the workflow file 'triage.yml' with JSON via standard input
89 $ echo '{"name":"scully", "greeting":"hello"}' | gh workflow run triage.yml --json
90 `),
91 Args: func(cmd *cobra.Command, args []string) error {
92 if len(opts.MagicFields)+len(opts.RawFields) > 0 && len(args) == 0 {
93 return cmdutil.FlagErrorf("workflow argument required when passing -f or -F")
94 }
95 return nil
96 },
97 RunE: func(cmd *cobra.Command, args []string) error {
98 // support `-R, --repo` override
99 opts.BaseRepo = f.BaseRepo
100
101 inputFieldsPassed := len(opts.MagicFields)+len(opts.RawFields) > 0
102
103 if len(args) > 0 {
104 opts.Selector = args[0]
105 } else if !opts.IO.CanPrompt() {
106 return cmdutil.FlagErrorf("workflow ID, name, or filename required when not running interactively")
107 } else {
108 opts.Prompt = true

Callers 1

TestNewCmdRunFunction · 0.70

Calls 5

FlagErrorfFunction · 0.92
runRunFunction · 0.85
CanPromptMethod · 0.80
IsStdinTTYMethod · 0.80

Tested by 1

TestNewCmdRunFunction · 0.56