Skip to content

feat: enhance UX of harp create project command #809

@hartym

Description

@hartym

Summary

Improve the harp create project command by allowing CLI arguments to avoid interactive prompts. Users can pass the project name directly, author info is auto-detected from git config, and flags control optional features.

Target UX:

# Create project with all defaults (app + config)
harp create project my-project

# Without application folder
harp create project my-project --no-app

# Without config file
harp create project my-project --no-config

Context

Current behavior prompts interactively for all values:

  • Project name
  • Author name (default: "Smart Anonymous Harpist")
  • Author email (default: "[email protected]")
  • Create application? (default: false)
  • Create config? (default: true)

Files involved:

  • harp/commandline/create.py - command implementation
  • harp/commandline/cookiecutters/project/cookiecutter.json - template config

Implementation

CLI Changes

@click.command("create")
@click.argument("template", type=click.Choice(["project"]))
@click.argument("name", required=False)
@click.option("--no-app", is_flag=True, help="Skip creating application folder")
@click.option("--no-config", is_flag=True, help="Skip creating config.yml")
def create(template, name, no_app, no_config):

Behavior

  1. Project name: Positional argument after template. If not provided, prompt interactively.

  2. Author info: Auto-detect from git config (git config user.name / git config user.email). Only prompt if git config is empty.

  3. Defaults changed:

    • create_application: true by default (was false)
    • create_config: true by default (unchanged)
  4. Flags:

    • --no-app: Set create_application=false
    • --no-config: Set create_config=false

Cookiecutter Integration

Use extra_context to pass pre-filled values and no_input=True when all required values are available:

import subprocess

def get_git_config(key):
    try:
        result = subprocess.run(["git", "config", key], capture_output=True, text=True)
        return result.stdout.strip() if result.returncode == 0 else None
    except FileNotFoundError:
        return None

extra_context = {
    "create_application": not no_app,
    "create_config": not no_config,
}

author_name = get_git_config("user.name")
author_email = get_git_config("user.email")

if author_name:
    extra_context["author_name"] = author_name
if author_email:
    extra_context["author_email"] = author_email
if name:
    extra_context["name"] = name

# Use no_input=True if all required values are provided
can_skip_prompts = name and author_name and author_email

cookiecutter(
    template_path,
    extra_context=extra_context,
    no_input=can_skip_prompts,
)

Update cookiecutter.json

Change create_application default from false to true:

{
  "create_application": true,
  "create_config": true
}

Testing Scenarios

  1. Full CLI args: harp create project my-proj with git config set → creates project without prompts
  2. No git config: harp create project my-proj without git config → prompts for author info only
  3. No name: harp create project → prompts for name (and author if no git config)
  4. With --no-app: Creates project without application folder
  5. With --no-config: Creates project without config.yml

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions