MCPcopy
hub / github.com/cli/cli / NewCmdWatch

Function NewCmdWatch

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

Source from the content-addressed store, hash-verified

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