feat(wt): moar help text!

Amolith created

Assisted-by: Claude Opus 4.5 via Amp

Change summary

src/main.lua | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+), 1 deletion(-)

Detailed changes

src/main.lua 🔗

@@ -141,10 +141,135 @@ local function print_usage()
 	print("  r <branch> [-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 <url> [--remote name]... [--own]",
+		"",
+		"Clone a repository into bare worktree structure.",
+		"",
+		"Arguments:",
+		"  <url>              Git URL to clone",
+		"",
+		"Options:",
+		"  --remote <name>    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 <project-name> [--remote name]...",
+		"",
+		"Initialize a fresh project with bare worktree structure.",
+		"",
+		"Arguments:",
+		"  <project-name>     Name of the new project directory",
+		"",
+		"Options:",
+		"  --remote <name>    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 <branch> [-b [<start-point>]]",
+		"",
+		"Add a worktree for a branch.",
+		"",
+		"Arguments:",
+		"  <branch>           Branch name to checkout or create",
+		"",
+		"Options:",
+		"  -b                 Create a new branch",
+		"  <start-point>      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 <branch> [-b] [-f]",
+		"",
+		"Remove a worktree.",
+		"",
+		"Arguments:",
+		"  <branch>           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