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

Function NewCmdWatch

pkg/cmd/run/watch/watch.go:42–104  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*WatchOptions) error)

Source from the content-addressed store, hash-verified

40}
41
42func NewCmdWatch(f *cmdutil.Factory, runF func(*WatchOptions) error) *cobra.Command {
43 opts := &WatchOptions{
44 IO: f.IOStreams,
45 HttpClient: f.HttpClient,
46 Prompter: f.Prompter,
47 Now: time.Now,
48
49 InvokingAgent: f.InvokingAgent,
50 }
51
52 cmd := &cobra.Command{
53 Use: "watch <run-id>",
54 Short: "Watch a run until it completes, showing its progress",
55 Long: heredoc.Docf(`
56 Watch a run until it completes, showing its progress.
57
58 By default, all steps are displayed. The %[1]s--compact%[1]s option can be used to only
59 show the relevant/failed steps.
60
61 This command does not support authenticating via fine grained PATs
62 as it is not currently possible to create a PAT with the %[1]schecks:read%[1]s permission.
63
64 This command polls the run. To wait for the workflow runs of a pull request on %[1]sgithub.com%[1]s to
65 finish without polling, use %[1]sgh event listen%[1]s with the
66 %[1]scom.github.pull_request.check_suite.status.changed.v1%[1]s event instead. Each check suite, such as a
67 workflow run, sends its own event when it completes. Changes made before the listener starts are not
68 reported, so read the checks once it is listening.
69 `, "`"),
70 Example: heredoc.Doc(`
71 # Watch a run until it's done
72 $ gh run watch
73
74 # Watch a run in compact mode
75 $ gh run watch --compact
76
77 # Run some other command when the run is finished
78 $ gh run watch && notify-send 'run is done!'
79 `),
80 RunE: func(cmd *cobra.Command, args []string) error {
81 // support `-R, --repo` override
82 opts.BaseRepo = f.BaseRepo
83
84 if len(args) > 0 {
85 opts.RunID = args[0]
86 } else if !opts.IO.CanPrompt() {
87 return cmdutil.FlagErrorf("run ID required when not running interactively")
88 } else {
89 opts.Prompt = true
90 }
91
92 if runF != nil {
93 return runF(opts)
94 }
95
96 return watchRun(opts)
97 },
98 }
99 cmd.Flags().BoolVar(&opts.ExitStatus, "exit-status", false, "Exit with non-zero status if run fails")

Callers 1

TestNewCmdWatchFunction · 0.85

Calls 3

FlagErrorfFunction · 0.92
watchRunFunction · 0.85
CanPromptMethod · 0.80

Tested by 1

TestNewCmdWatchFunction · 0.68