Repository: cli/cli
File: pkg/cmd/agent-task/create/create.go (Go)

Code before:
	cmd.Flags().StringVarP(&fromFileName, "from-file", "F", "", "Read task description from `file` (use \"-\" to read from standard input)")
	cmd.Flags().StringVarP(&opts.BaseBranch, "base", "b", "", "Base branch for the pull request (use default branch if not provided)")

	return cmd
}

func createRun(opts *CreateOptions) error {
	repo, err := opts.BaseRepo()
	if err != nil || repo == nil {
		// Not printing the error that came back from BaseRepo() here because we want
		// something clear, human friendly, and actionable.
		return fmt.Errorf("a repository is required; re-run in a repository or supply one with --repo owner/name")
	}

	// Prompt for ProblemStatement if not provided non-interactively
	if opts.Prompter != nil && opts.IO.CanPrompt() {
		desc, err := opts.Prompter.MarkdownEditor("Enter the task description", opts.ProblemStatement, false)
		if err != nil {
			return err
		}
		trimmed := strings.TrimSpace(desc)
		if trimmed == "" {
			return cmdutil.FlagErrorf("a task description is required")
		}
		opts.ProblemStatement = trimmed
	}

	if opts.ProblemStatement == "" {
		return cmdutil.FlagErrorf("a task description or -F is required when running non-interactively")
	}

	client, err := opts.CapiClient()
	if err != nil {
		return err
	}

	ctx := context.Background()
	opts.IO.StartProgressIndicatorWithLabel(fmt.Sprintf("Creating agent task in %s/%s...", repo.RepoOwner(), repo.RepoName()))
	defer opts.IO.StopProgressIndicator()

	job, err := client.CreateJob(ctx, repo.RepoOwner(), repo.RepoName(), opts.ProblemStatement, opts.BaseBranch)
	if err != nil {
		return err
	}

	// Print this agent session URL and exit if we happen to get it.
	// Right now, this never happens.
	if job.PullRequest != nil && job.PullRequest.Number > 0 {
		fmt.Fprintf(opts.IO.Out, "%s\n", agentSessionWebURL(repo, job))
		return nil
	}

Review comment (suggestion):
This has to be predicated to `opts.ProblemStatement == ""`. It's now breaking the behaviour with an arg (i.e. `agent-task create 'foo'`). 

The reasons this is not surfaced by the tests is the `if opts.Prompter != nil` part, which skips the entire prompting code path if the mock prompter is not provided. I think it's best to assume `opts.Prompter` is never `nil` (because at runtime it's not `nil`), and let the tests discover such issues.

Code after:
	cmd.Flags().StringVarP(&fromFileName, "from-file", "F", "", "Read task description from `file` (use \"-\" to read from standard input)")
	cmd.Flags().StringVarP(&opts.BaseBranch, "base", "b", "", "Base branch for the pull request (use default branch if not provided)")

	return cmd
}

func createRun(opts *CreateOptions) error {
	repo, err := opts.BaseRepo()
	if err != nil || repo == nil {
		// Not printing the error that came back from BaseRepo() here because we want
		// something clear, human friendly, and actionable.
		return fmt.Errorf("a repository is required; re-run in a repository or supply one with --repo owner/name")
	}

	if opts.ProblemStatement == "" {
		if !opts.IO.CanPrompt() {
			return cmdutil.FlagErrorf("a task description or -F is required when running non-interactively")
		}

		desc, err := opts.Prompter.MarkdownEditor("Enter the task description", opts.ProblemStatement, false)
		if err != nil {
			return err
		}

		trimmed := strings.TrimSpace(desc)
		if trimmed == "" {
			return cmdutil.FlagErrorf("a task description is required")
		}
		opts.ProblemStatement = trimmed
	}

	client, err := opts.CapiClient()
	if err != nil {
		return err
	}

	ctx := context.Background()
	opts.IO.StartProgressIndicatorWithLabel(fmt.Sprintf("Creating agent task in %s/%s...", repo.RepoOwner(), repo.RepoName()))
	defer opts.IO.StopProgressIndicator()

	job, err := client.CreateJob(ctx, repo.RepoOwner(), repo.RepoName(), opts.ProblemStatement, opts.BaseBranch)
	if err != nil {
		return err
	}

	// Print this agent session URL and exit if we happen to get it.
	// Right now, this never happens.
	if job.PullRequest != nil && job.PullRequest.Number > 0 {
		fmt.Fprintf(opts.IO.Out, "%s\n", agentSessionWebURL(repo, job))
		return nil
	}