From 8198c5db54c8e11f829ba4674dd98ed1e2ef8329 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sun, 18 Jan 2026 08:15:34 -0700 Subject: [PATCH] feat(wt): moar help text! Assisted-by: Claude Opus 4.5 via Amp --- src/main.lua | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/src/main.lua b/src/main.lua index 910bf16f3714d6098f6ad130d46f1d44ee15b68d..e897e28dbac278b29b4af7a924e6f212e3288e73 100644 --- a/src/main.lua +++ b/src/main.lua @@ -141,10 +141,135 @@ local function print_usage() print(" r [-b] [-f] Remove worktree, optionally delete branch") print(" l List worktrees with status") print(" f Fetch all remotes") - print(" init [--dry-run] [-y] Convert existing repo to bare structure") + print(" init [--dry-run] [-y] Convert existing repo to bare structure") print(" help Show this help message") end +-- Per-command help text (using table.concat for performance) +local COMMAND_HELP = { + c = table.concat({ + "wt c [--remote name]... [--own]", + "", + "Clone a repository into bare worktree structure.", + "", + "Arguments:", + " Git URL to clone", + "", + "Options:", + " --remote Add configured remote from ~/.config/wt/config.lua", + " Can be specified multiple times", + " --own Treat as your own project: first remote becomes 'origin'", + " (default: 'origin' renamed to 'upstream', your remotes added)", + "", + "Examples:", + " wt c https://github.com/user/repo.git", + " wt c git@github.com:user/repo.git --remote github --own", + }, "\n"), + + n = table.concat({ + "wt n [--remote name]...", + "", + "Initialize a fresh project with bare worktree structure.", + "", + "Arguments:", + " Name of the new project directory", + "", + "Options:", + " --remote Add configured remote from ~/.config/wt/config.lua", + " Can be specified multiple times", + "", + "Examples:", + " wt n my-project", + " wt n my-project --remote github --remote gitlab", + }, "\n"), + + a = table.concat({ + "wt a [-b []]", + "", + "Add a worktree for a branch.", + "", + "Arguments:", + " Branch name to checkout or create", + "", + "Options:", + " -b Create a new branch", + " Base commit/branch for new branch (only with -b)", + "", + "If run from inside an existing worktree, hooks from .wt.lua will be applied.", + "", + "Examples:", + " wt a main # Checkout existing branch", + " wt a feature/new -b # Create new branch from HEAD", + " wt a feature/new -b main # Create new branch from main", + }, "\n"), + + r = table.concat({ + "wt r [-b] [-f]", + "", + "Remove a worktree.", + "", + "Arguments:", + " Branch name of worktree to remove", + "", + "Options:", + " -b Also delete the branch after removing worktree", + " -f Force removal even with uncommitted changes", + "", + "Examples:", + " wt r feature/old # Remove worktree, keep branch", + " wt r feature/old -b # Remove worktree and delete branch", + " wt r feature/old -f # Force remove with uncommitted changes", + }, "\n"), + + l = table.concat({ + "wt l", + "", + "List all worktrees with status information.", + "", + "Displays a table showing:", + " - Branch name", + " - Relative path from project root", + " - Commit status (ahead/behind remote)", + " - Working tree status (clean/dirty)", + }, "\n"), + + f = table.concat({ + "wt f", + "", + "Fetch from all configured remotes.", + "", + "Runs 'git fetch --all' in the bare repository.", + }, "\n"), + + init = table.concat({ + "wt init [--dry-run] [-y]", + "", + "Convert an existing git repository to bare worktree structure.", + "", + "Options:", + " --dry-run Show what would be done without making changes", + " -y Skip confirmation prompt", + "", + "This command:", + " 1. Moves .git/ to .bare/", + " 2. Creates .git file pointing to .bare/", + " 3. Creates a worktree for the current branch", + " 4. Removes orphaned files from project root", + }, "\n"), +} + +---Show help for a specific command +---@param cmd string +local function show_command_help(cmd) + local help = COMMAND_HELP[cmd] + if help then + print(help) + else + print_usage() + end + os.exit(EXIT_SUCCESS) +end + ---Parse git URLs to extract project name (exported version) ---@param url string ---@return string|nil @@ -1646,6 +1771,11 @@ local function main() table.insert(subargs, arg[i]) end + -- Check for --help on any command + if subargs[1] == "--help" or subargs[1] == "-h" then + show_command_help(command) + end + if command == "c" then cmd_clone(subargs) elseif command == "n" then