NewCmdAgentTask creates the base `agent-task` command.
(f *cmdutil.Factory)
| 16 | |
| 17 | // NewCmdAgentTask creates the base `agent-task` command. |
| 18 | func NewCmdAgentTask(f *cmdutil.Factory) *cobra.Command { |
| 19 | cmd := &cobra.Command{ |
| 20 | Use: "agent-task <command>", |
| 21 | Aliases: []string{"agent-tasks", "agent", "agents"}, |
| 22 | Short: "Work with agent tasks (preview)", |
| 23 | Long: heredoc.Doc(` |
| 24 | Working with agent tasks in the GitHub CLI is in preview and |
| 25 | subject to change without notice. |
| 26 | `), |
| 27 | Annotations: map[string]string{ |
| 28 | "help:arguments": heredoc.Doc(` |
| 29 | A task can be identified as argument in any of the following formats: |
| 30 | - by pull request number, e.g. "123"; or |
| 31 | - by session ID, e.g. "12345abc-12345-12345-12345-12345abc"; or |
| 32 | - by URL, e.g. "https://github.com/OWNER/REPO/pull/123/agent-sessions/12345abc-12345-12345-12345-12345abc"; |
| 33 | |
| 34 | Identifying tasks by pull request is not recommended for non-interactive use cases as |
| 35 | there may be multiple tasks for a given pull request that require disambiguation. |
| 36 | `), |
| 37 | }, |
| 38 | Example: heredoc.Doc(` |
| 39 | # List your most recent agent tasks |
| 40 | $ gh agent-task list |
| 41 | |
| 42 | # Create a new agent task on the current repository |
| 43 | $ gh agent-task create "Improve the performance of the data processing pipeline" |
| 44 | |
| 45 | # View details about agent tasks associated with a pull request |
| 46 | $ gh agent-task view 123 |
| 47 | |
| 48 | # View details about a specific agent task |
| 49 | $ gh agent-task view 12345abc-12345-12345-12345-12345abc |
| 50 | `), |
| 51 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 52 | return requireOAuthToken(f) |
| 53 | }, |
| 54 | // This is required to run this root command. We want to |
| 55 | // run it to test PersistentPreRunE behavior. |
| 56 | RunE: func(cmd *cobra.Command, args []string) error { |
| 57 | return cmd.Help() |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | // register subcommands |
| 62 | cmd.AddCommand(cmdList.NewCmdList(f, nil)) |
| 63 | cmd.AddCommand(cmdCreate.NewCmdCreate(f, nil)) |
| 64 | cmd.AddCommand(cmdView.NewCmdView(f, nil)) |
| 65 | |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | // requireOAuthToken ensures an OAuth (device flow) token is present and valid. |
| 70 | // agent-task subcommands inherit this check via PersistentPreRunE. |