| 55 | } |
| 56 | |
| 57 | func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { |
| 58 | opts := &ViewOptions{ |
| 59 | IO: f.IOStreams, |
| 60 | HttpClient: f.HttpClient, |
| 61 | CapiClient: shared.CapiClientFunc(f), |
| 62 | Prompter: f.Prompter, |
| 63 | Browser: f.Browser, |
| 64 | LogRenderer: defaultLogRenderer, |
| 65 | Sleep: time.Sleep, |
| 66 | } |
| 67 | |
| 68 | cmd := &cobra.Command{ |
| 69 | Use: "view [<session-id> | <pr-number> | <pr-url> | <pr-branch>]", |
| 70 | Short: "View an agent task session (preview)", |
| 71 | Long: heredoc.Doc(` |
| 72 | View an agent task session. |
| 73 | `), |
| 74 | Example: heredoc.Doc(` |
| 75 | # View an agent task by session ID |
| 76 | $ gh agent-task view e2fa49d2-f164-4a56-ab99-498090b8fcdf |
| 77 | |
| 78 | # View an agent task by pull request number in current repo |
| 79 | $ gh agent-task view 12345 |
| 80 | |
| 81 | # View an agent task by pull request number |
| 82 | $ gh agent-task view --repo OWNER/REPO 12345 |
| 83 | |
| 84 | # View an agent task by pull request reference |
| 85 | $ gh agent-task view OWNER/REPO#12345 |
| 86 | |
| 87 | # View a pull request agents tasks in the browser |
| 88 | $ gh agent-task view 12345 --web |
| 89 | `), |
| 90 | Args: cobra.MaximumNArgs(1), |
| 91 | RunE: func(cmd *cobra.Command, args []string) error { |
| 92 | // Support -R/--repo override |
| 93 | opts.BaseRepo = f.BaseRepo |
| 94 | |
| 95 | if len(args) > 0 { |
| 96 | opts.SelectorArg = args[0] |
| 97 | if shared.IsSessionID(opts.SelectorArg) { |
| 98 | opts.SessionID = opts.SelectorArg |
| 99 | } else if sessionID, err := shared.ParseSessionIDFromURL(opts.SelectorArg); err == nil { |
| 100 | opts.SessionID = sessionID |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if opts.SessionID == "" && !opts.IO.CanPrompt() { |
| 105 | return fmt.Errorf("session ID is required when not running interactively") |
| 106 | } |
| 107 | |
| 108 | if opts.Follow && !opts.Log { |
| 109 | return cmdutil.FlagErrorf("--log is required when providing --follow") |
| 110 | } |
| 111 | |
| 112 | if opts.Finder == nil { |
| 113 | opts.Finder = prShared.NewFinder(f) |
| 114 | } |