mirror of
https://github.com/github/spec-kit.git
synced 2026-02-04 15:03:07 +00:00
Cleanup
This commit is contained in:
@@ -64,7 +64,6 @@ def _github_auth_headers(cli_token: str | None = None) -> dict:
|
||||
token = _github_token(cli_token)
|
||||
return {"Authorization": f"Bearer {token}"} if token else {}
|
||||
|
||||
# Constants
|
||||
AI_CHOICES = {
|
||||
"copilot": "GitHub Copilot",
|
||||
"claude": "Claude Code",
|
||||
@@ -79,13 +78,11 @@ AI_CHOICES = {
|
||||
"roo": "Roo Code",
|
||||
"q": "Amazon Q Developer CLI",
|
||||
}
|
||||
# Add script type choices
|
||||
|
||||
SCRIPT_TYPE_CHOICES = {"sh": "POSIX Shell (bash/zsh)", "ps": "PowerShell"}
|
||||
|
||||
# Claude CLI local installation path after migrate-installer
|
||||
CLAUDE_LOCAL_PATH = Path.home() / ".claude" / "local" / "claude"
|
||||
|
||||
# ASCII Art Banner
|
||||
BANNER = """
|
||||
███████╗██████╗ ███████╗ ██████╗██╗███████╗██╗ ██╗
|
||||
██╔════╝██╔══██╗██╔════╝██╔════╝██║██╔════╝╚██╗ ██╔╝
|
||||
@@ -182,40 +179,26 @@ class StepTracker:
|
||||
tree.add(line)
|
||||
return tree
|
||||
|
||||
|
||||
|
||||
MINI_BANNER = """
|
||||
╔═╗╔═╗╔═╗╔═╗╦╔═╗╦ ╦
|
||||
╚═╗╠═╝║╣ ║ ║╠╣ ╚╦╝
|
||||
╚═╝╩ ╚═╝╚═╝╩╚ ╩
|
||||
"""
|
||||
|
||||
def get_key():
|
||||
"""Get a single keypress in a cross-platform way using readchar."""
|
||||
key = readchar.readkey()
|
||||
|
||||
# Arrow keys
|
||||
if key == readchar.key.UP or key == readchar.key.CTRL_P:
|
||||
return 'up'
|
||||
if key == readchar.key.DOWN or key == readchar.key.CTRL_N:
|
||||
return 'down'
|
||||
|
||||
# Enter/Return
|
||||
if key == readchar.key.ENTER:
|
||||
return 'enter'
|
||||
|
||||
# Escape
|
||||
if key == readchar.key.ESC:
|
||||
return 'escape'
|
||||
|
||||
# Ctrl+C
|
||||
if key == readchar.key.CTRL_C:
|
||||
raise KeyboardInterrupt
|
||||
|
||||
return key
|
||||
|
||||
|
||||
|
||||
def select_with_arrows(options: dict, prompt_text: str = "Select an option", default_key: str = None) -> str:
|
||||
"""
|
||||
Interactive selection using arrow keys with Rich Live display.
|
||||
@@ -292,11 +275,8 @@ def select_with_arrows(options: dict, prompt_text: str = "Select an option", def
|
||||
# Suppress explicit selection print; tracker / later logic will report consolidated status
|
||||
return selected_key
|
||||
|
||||
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
class BannerGroup(TyperGroup):
|
||||
"""Custom group that shows banner before help."""
|
||||
|
||||
@@ -314,7 +294,6 @@ app = typer.Typer(
|
||||
cls=BannerGroup,
|
||||
)
|
||||
|
||||
|
||||
def show_banner():
|
||||
"""Display the ASCII art banner."""
|
||||
# Create gradient effect with different colors
|
||||
@@ -330,7 +309,6 @@ def show_banner():
|
||||
console.print(Align.center(Text(TAGLINE, style="italic bright_yellow")))
|
||||
console.print()
|
||||
|
||||
|
||||
@app.callback()
|
||||
def callback(ctx: typer.Context):
|
||||
"""Show banner when no subcommand is provided."""
|
||||
@@ -341,7 +319,6 @@ def callback(ctx: typer.Context):
|
||||
console.print(Align.center("[dim]Run 'specify --help' for usage information[/dim]"))
|
||||
console.print()
|
||||
|
||||
|
||||
def run_command(cmd: list[str], check_return: bool = True, capture: bool = False, shell: bool = False) -> Optional[str]:
|
||||
"""Run a shell command and optionally capture output."""
|
||||
try:
|
||||
@@ -360,7 +337,6 @@ def run_command(cmd: list[str], check_return: bool = True, capture: bool = False
|
||||
raise
|
||||
return None
|
||||
|
||||
|
||||
def check_tool_for_tracker(tool: str, tracker: StepTracker) -> bool:
|
||||
"""Check if a tool is installed and update tracker."""
|
||||
if shutil.which(tool):
|
||||
@@ -370,7 +346,6 @@ def check_tool_for_tracker(tool: str, tracker: StepTracker) -> bool:
|
||||
tracker.error(tool, "not found")
|
||||
return False
|
||||
|
||||
|
||||
def check_tool(tool: str, install_hint: str) -> bool:
|
||||
"""Check if a tool is installed."""
|
||||
|
||||
@@ -388,7 +363,6 @@ def check_tool(tool: str, install_hint: str) -> bool:
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def is_git_repo(path: Path = None) -> bool:
|
||||
"""Check if the specified path is inside a git repository."""
|
||||
if path is None:
|
||||
@@ -409,7 +383,6 @@ def is_git_repo(path: Path = None) -> bool:
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
return False
|
||||
|
||||
|
||||
def init_git_repo(project_path: Path, quiet: bool = False) -> bool:
|
||||
"""Initialize a git repository in the specified path.
|
||||
quiet: if True suppress console output (tracker handles status)
|
||||
@@ -433,7 +406,6 @@ def init_git_repo(project_path: Path, quiet: bool = False) -> bool:
|
||||
finally:
|
||||
os.chdir(original_cwd)
|
||||
|
||||
|
||||
def download_template_from_github(ai_assistant: str, download_dir: Path, *, script_type: str = "sh", verbose: bool = True, show_progress: bool = True, client: httpx.Client = None, debug: bool = False, github_token: str = None) -> Tuple[Path, dict]:
|
||||
repo_owner = "github"
|
||||
repo_name = "spec-kit"
|
||||
@@ -545,7 +517,6 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
|
||||
}
|
||||
return zip_path, metadata
|
||||
|
||||
|
||||
def download_and_extract_template(project_path: Path, ai_assistant: str, script_type: str, is_current_dir: bool = False, *, verbose: bool = True, tracker: StepTracker | None = None, client: httpx.Client = None, debug: bool = False, github_token: str = None) -> Path:
|
||||
"""Download the latest release and extract it to create a new project.
|
||||
Returns project_path. Uses tracker if provided (with keys: fetch, download, extract, cleanup)
|
||||
@@ -775,15 +746,7 @@ def init(
|
||||
Examples:
|
||||
specify init my-project
|
||||
specify init my-project --ai claude
|
||||
specify init my-project --ai gemini
|
||||
specify init my-project --ai copilot --no-git
|
||||
specify init my-project --ai cursor
|
||||
specify init my-project --ai qwen
|
||||
specify init my-project --ai opencode
|
||||
specify init my-project --ai codex
|
||||
specify init my-project --ai windsurf
|
||||
specify init my-project --ai auggie
|
||||
specify init my-project --ai q
|
||||
specify init --ignore-agent-tools my-project
|
||||
specify init . --ai claude # Initialize in current directory
|
||||
specify init . # Initialize in current directory (interactive AI selection)
|
||||
@@ -792,7 +755,7 @@ def init(
|
||||
specify init --here
|
||||
specify init --here --force # Skip confirmation when current directory not empty
|
||||
"""
|
||||
# Show banner first
|
||||
|
||||
show_banner()
|
||||
|
||||
# Handle '.' as shorthand for current directory (equivalent to --here)
|
||||
@@ -800,7 +763,6 @@ def init(
|
||||
here = True
|
||||
project_name = None # Clear project_name to use existing validation logic
|
||||
|
||||
# Validate arguments
|
||||
if here and project_name:
|
||||
console.print("[red]Error:[/red] Cannot specify both project name and --here flag")
|
||||
raise typer.Exit(1)
|
||||
@@ -809,12 +771,10 @@ def init(
|
||||
console.print("[red]Error:[/red] Must specify either a project name, use '.' for current directory, or use --here flag")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Determine project directory
|
||||
if here:
|
||||
project_name = Path.cwd().name
|
||||
project_path = Path.cwd()
|
||||
|
||||
# Check if current directory has any files
|
||||
existing_items = list(project_path.iterdir())
|
||||
if existing_items:
|
||||
console.print(f"[yellow]Warning:[/yellow] Current directory is not empty ({len(existing_items)} items)")
|
||||
@@ -822,14 +782,12 @@ def init(
|
||||
if force:
|
||||
console.print("[cyan]--force supplied: skipping confirmation and proceeding with merge[/cyan]")
|
||||
else:
|
||||
# Ask for confirmation
|
||||
response = typer.confirm("Do you want to continue?")
|
||||
if not response:
|
||||
console.print("[yellow]Operation cancelled[/yellow]")
|
||||
raise typer.Exit(0)
|
||||
else:
|
||||
project_path = Path(project_name).resolve()
|
||||
# Check if project directory already exists
|
||||
if project_path.exists():
|
||||
error_panel = Panel(
|
||||
f"Directory '[cyan]{project_name}[/cyan]' already exists\n"
|
||||
@@ -842,7 +800,6 @@ def init(
|
||||
console.print(error_panel)
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Create formatted setup info with column alignment
|
||||
current_dir = Path.cwd()
|
||||
|
||||
setup_lines = [
|
||||
@@ -866,7 +823,6 @@ def init(
|
||||
if not should_init_git:
|
||||
console.print("[yellow]Git not found - will skip repository initialization[/yellow]")
|
||||
|
||||
# AI assistant selection
|
||||
if ai_assistant:
|
||||
if ai_assistant not in AI_CHOICES:
|
||||
console.print(f"[red]Error:[/red] Invalid AI assistant '{ai_assistant}'. Choose from: {', '.join(AI_CHOICES.keys())}")
|
||||
@@ -1141,10 +1097,8 @@ def check():
|
||||
if not (claude_ok or gemini_ok or cursor_ok or qwen_ok or windsurf_ok or kilocode_ok or opencode_ok or codex_ok or auggie_ok or q_ok):
|
||||
console.print("[dim]Tip: Install an AI assistant for the best experience[/dim]")
|
||||
|
||||
|
||||
def main():
|
||||
app()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user