MCPcopy Index your code
hub / github.com/cli/cli / NewCmdRun

Function NewCmdRun

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

Source from the content-addressed store, hash-verified

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