MCPcopy
hub / github.com/cli/cli / NewCmdCreate

Function NewCmdCreate

pkg/cmd/agent-task/create/create.go:49–121  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*CreateOptions) error)

Source from the content-addressed store, hash-verified

47}
48
49func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
50 opts := &CreateOptions{
51 IO: f.IOStreams,
52 CapiClient: shared.CapiClientFunc(f),
53 Config: f.Config,
54 Prompter: f.Prompter,
55 LogRenderer: defaultLogRenderer,
56 Sleep: time.Sleep,
57 }
58
59 cmd := &cobra.Command{
60 Use: "create [<task description>] [flags]",
61 Short: "Create an agent task (preview)",
62 Args: cobra.MaximumNArgs(1),
63 RunE: func(cmd *cobra.Command, args []string) error {
64 // Support -R/--repo override
65 opts.BaseRepo = f.BaseRepo
66
67 if err := cmdutil.MutuallyExclusive("only one of -F or arg can be provided", len(args) > 0, opts.ProblemStatementFile != ""); err != nil {
68 return err
69 }
70
71 // Populate ProblemStatement from arg
72 if len(args) > 0 {
73 opts.ProblemStatement = args[0]
74 if strings.TrimSpace(opts.ProblemStatement) == "" {
75 return cmdutil.FlagErrorf("task description cannot be empty")
76 }
77 } else if opts.ProblemStatementFile == "" && !opts.IO.CanPrompt() {
78 return cmdutil.FlagErrorf("a task description or -F is required when running non-interactively")
79 }
80
81 if runF != nil {
82 return runF(opts)
83 }
84 return createRun(opts)
85 },
86 Example: heredoc.Doc(`
87 # Create a task from an inline description
88 $ gh agent-task create "build me a new app"
89
90 # Create a task from an inline description and follow logs
91 $ gh agent-task create "build me a new app" --follow
92
93 # Create a task from a file
94 $ gh agent-task create -F task-desc.md
95
96 # Create a task with problem statement from stdin
97 $ echo "build me a new app" | gh agent-task create -F -
98
99 # Create a task with an editor
100 $ gh agent-task create
101
102 # Create a task with an editor and a file as a template
103 $ gh agent-task create -F task-desc.md
104
105 # Select a different base branch for the PR
106 $ gh agent-task create "fix errors" --base branch

Callers 1

TestNewCmdCreateFunction · 0.70

Calls 6

CapiClientFuncFunction · 0.92
MutuallyExclusiveFunction · 0.92
FlagErrorfFunction · 0.92
EnableRepoOverrideFunction · 0.92
CanPromptMethod · 0.80
createRunFunction · 0.70

Tested by 1

TestNewCmdCreateFunction · 0.56