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

Function NewCmdWatch

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

Source from the content-addressed store, hash-verified

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