Repository: cli/cli
File: pkg/cmd/run/watch/watch.go (Go)

Code before:

	Prompt bool

	Now func() time.Time
}

func NewCmdWatch(f *cmdutil.Factory, runF func(*WatchOptions) error) *cobra.Command {
	opts := &WatchOptions{
		IO:         f.IOStreams,
		HttpClient: f.HttpClient,
		Prompter:   f.Prompter,
		Now:        time.Now,
	}

	cmd := &cobra.Command{
		Use:   "watch <run-id>",
		Short: "Watch a run until it completes, showing its progress",
		Long: heredoc.Docf(`
			Watch a run until it completes, showing its progress.

			By default, all the steps are shown with each refresh.
			With the %[1]s--compact%[1]s flag:
			- For a successfully completed job, not steps are shown.
			- For a failed job, all the failed steps are shown.
			- For an ongoing job with no failed steps, only the currently running step is shown.
			- For an ongoing job with failed steps, the failed steps along with the currently running step are shown.

			This command does not support authenticating via fine grained PATs
			as it is not currently possible to create a PAT with the %[1]schecks:read%[1]s permission.
		`, "`"),
		Example: heredoc.Doc(`
			# Watch a run until it's done
			$ gh run watch

			# Run some other command when the run is finished
			$ gh run watch && notify-send 'run is done!'

			# Watch a run in compact mode
			$ gh run watch --compact
		`),
		RunE: func(cmd *cobra.Command, args []string) error {
			// support `-R, --repo` override
			opts.BaseRepo = f.BaseRepo

			if len(args) > 0 {
				opts.RunID = args[0]
			} else if !opts.IO.CanPrompt() {
				return cmdutil.FlagErrorf("run ID required when not running interactively")
			} else {
				opts.Prompt = true
			}

Review comment (bug):
IMO the user doesn't need to see the details of the `--compact` mode here. Just saying it removes irrelevant steps from the output is enough.


```suggestion
			By default, all steps are displayed. The %[1]s--compact%[1]s option can be used
			to only show the relevant/failed steps.
```

Code after:

	Prompt bool

	Now func() time.Time
}

func NewCmdWatch(f *cmdutil.Factory, runF func(*WatchOptions) error) *cobra.Command {
	opts := &WatchOptions{
		IO:         f.IOStreams,
		HttpClient: f.HttpClient,
		Prompter:   f.Prompter,
		Now:        time.Now,
	}

	cmd := &cobra.Command{
		Use:   "watch <run-id>",
		Short: "Watch a run until it completes, showing its progress",
		Long: heredoc.Docf(`
			Watch a run until it completes, showing its progress.

			By default, all steps are displayed. The %[1]s--compact%[1]s option can be used to only
			show the relevant/failed steps.

			This command does not support authenticating via fine grained PATs
			as it is not currently possible to create a PAT with the %[1]schecks:read%[1]s permission.
		`, "`"),
		Example: heredoc.Doc(`
			# Watch a run until it's done
			$ gh run watch

			# Watch a run in compact mode
			$ gh run watch --compact

			# Run some other command when the run is finished
			$ gh run watch && notify-send 'run is done!'
		`),
		RunE: func(cmd *cobra.Command, args []string) error {
			// support `-R, --repo` override
			opts.BaseRepo = f.BaseRepo

			if len(args) > 0 {
				opts.RunID = args[0]
			} else if !opts.IO.CanPrompt() {
				return cmdutil.FlagErrorf("run ID required when not running interactively")
			} else {
				opts.Prompt = true
			}

			if runF != nil {
				return runF(opts)
			}