-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Milestone
Description
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-configContext
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 implementationharp/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
-
Project name: Positional argument after template. If not provided, prompt interactively.
-
Author info: Auto-detect from git config (
git config user.name/git config user.email). Only prompt if git config is empty. -
Defaults changed:
create_application: true by default (was false)create_config: true by default (unchanged)
-
Flags:
--no-app: Setcreate_application=false--no-config: Setcreate_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
- Full CLI args:
harp create project my-projwith git config set → creates project without prompts - No git config:
harp create project my-projwithout git config → prompts for author info only - No name:
harp create project→ prompts for name (and author if no git config) - With --no-app: Creates project without application folder
- With --no-config: Creates project without config.yml