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

Function NewCmdWatch

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

Source from the content-addressed store, hash-verified

37}
38
39func NewCmdWatch(f *cmdutil.Factory, runF func(*WatchOptions) error) *cobra.Command {
40 opts := &WatchOptions{
41 IO: f.IOStreams,
42 HttpClient: f.HttpClient,
43 Prompter: f.Prompter,
44 Now: time.Now,
45 }
46
47 cmd := &cobra.Command{
48 Use: "watch <run-id>",
49 Short: "Watch a run until it completes, showing its progress",
50 Long: heredoc.Docf(`
51 Watch a run until it completes, showing its progress.
52
53 By default, all steps are displayed. The %[1]s--compact%[1]s option can be used to only
54 show the relevant/failed steps.
55
56 This command does not support authenticating via fine grained PATs
57 as it is not currently possible to create a PAT with the %[1]schecks:read%[1]s permission.
58 `, "`"),
59 Example: heredoc.Doc(`
60 # Watch a run until it's done
61 $ gh run watch
62
63 # Watch a run in compact mode
64 $ gh run watch --compact
65
66 # Run some other command when the run is finished
67 $ gh run watch && notify-send 'run is done!'
68 `),
69 RunE: func(cmd *cobra.Command, args []string) error {
70 // support `-R, --repo` override
71 opts.BaseRepo = f.BaseRepo
72
73 if len(args) > 0 {
74 opts.RunID = args[0]
75 } else if !opts.IO.CanPrompt() {
76 return cmdutil.FlagErrorf("run ID required when not running interactively")
77 } else {
78 opts.Prompt = true
79 }
80
81 if runF != nil {
82 return runF(opts)
83 }
84
85 return watchRun(opts)
86 },
87 }
88 cmd.Flags().BoolVar(&opts.ExitStatus, "exit-status", false, "Exit with non-zero status if run fails")
89 cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Show only relevant/failed steps")
90 cmd.Flags().IntVarP(&opts.Interval, "interval", "i", defaultInterval, "Refresh interval in seconds")
91
92 return cmd
93}
94
95func watchRun(opts *WatchOptions) error {
96 c, err := opts.HttpClient()

Callers 1

TestNewCmdWatchFunction · 0.85

Calls 3

FlagErrorfFunction · 0.92
watchRunFunction · 0.85
CanPromptMethod · 0.80

Tested by 1

TestNewCmdWatchFunction · 0.68