|
5 | 5 | module Git |
6 | 6 | module Pkgs |
7 | 7 | class CLI |
8 | | - COMMANDS = %w[init update hooks info list tree history search where why blame stale stats diff branch show log upgrade schema diff-driver].freeze |
| 8 | + COMMAND_GROUPS = { |
| 9 | + "Setup" => { |
| 10 | + "init" => "Initialize the package database for this repository", |
| 11 | + "update" => "Update the database with new commits", |
| 12 | + "hooks" => "Manage git hooks for auto-updating", |
| 13 | + "upgrade" => "Upgrade database after git-pkgs update", |
| 14 | + "info" => "Show database size and row counts", |
| 15 | + "branch" => "Manage tracked branches", |
| 16 | + "schema" => "Show database schema", |
| 17 | + "diff-driver" => "Install git textconv driver for lockfile diffs" |
| 18 | + }, |
| 19 | + "Query" => { |
| 20 | + "list" => "List dependencies at a commit", |
| 21 | + "tree" => "Show dependency tree grouped by type", |
| 22 | + "search" => "Find a dependency across all history", |
| 23 | + "where" => "Show where a package appears in manifest files", |
| 24 | + "why" => "Explain why a dependency exists" |
| 25 | + }, |
| 26 | + "History" => { |
| 27 | + "history" => "Show the history of a package", |
| 28 | + "blame" => "Show who added each dependency", |
| 29 | + "log" => "List commits with dependency changes", |
| 30 | + "show" => "Show dependency changes in a commit", |
| 31 | + "diff" => "Show dependency changes between commits" |
| 32 | + }, |
| 33 | + "Analysis" => { |
| 34 | + "stats" => "Show dependency statistics", |
| 35 | + "stale" => "Show dependencies that haven't been updated" |
| 36 | + } |
| 37 | + }.freeze |
| 38 | + |
| 39 | + COMMANDS = COMMAND_GROUPS.values.flat_map(&:keys).freeze |
| 40 | + COMMAND_DESCRIPTIONS = COMMAND_GROUPS.values.reduce({}, :merge).freeze |
9 | 41 | ALIASES = { "praise" => "blame", "outdated" => "stale" }.freeze |
10 | 42 |
|
11 | 43 | def self.run(args) |
@@ -46,36 +78,24 @@ def run_command(command) |
46 | 78 | end |
47 | 79 |
|
48 | 80 | def print_help |
49 | | - puts <<~HELP |
50 | | - Usage: git pkgs <command> [options] |
| 81 | + puts "Usage: git pkgs <command> [options]" |
| 82 | + puts |
51 | 83 |
|
52 | | - Commands: |
53 | | - init Initialize the package database for this repository |
54 | | - update Update the database with new commits |
55 | | - hooks Manage git hooks for auto-updating |
56 | | - info Show database size and row counts |
57 | | - branch Manage tracked branches |
58 | | - list List dependencies at a commit |
59 | | - tree Show dependency tree grouped by type |
60 | | - history Show the history of a package |
61 | | - search Find a dependency across all history |
62 | | - where Show where a package appears in manifest files |
63 | | - why Explain why a dependency exists |
64 | | - blame Show who added each dependency |
65 | | - stale Show dependencies that haven't been updated |
66 | | - stats Show dependency statistics |
67 | | - diff Show dependency changes between commits |
68 | | - show Show dependency changes in a commit |
69 | | - log List commits with dependency changes |
70 | | - upgrade Upgrade database after git-pkgs update |
71 | | - schema Show database schema |
| 84 | + max_cmd_len = COMMANDS.map(&:length).max |
72 | 85 |
|
73 | | - Options: |
74 | | - -h, --help Show this help message |
75 | | - -v, --version Show version |
| 86 | + COMMAND_GROUPS.each do |group, commands| |
| 87 | + puts "#{group}:" |
| 88 | + commands.each do |cmd, desc| |
| 89 | + puts " #{cmd.ljust(max_cmd_len)} #{desc}" |
| 90 | + end |
| 91 | + puts |
| 92 | + end |
76 | 93 |
|
77 | | - Run 'git pkgs <command> --help' for command-specific options. |
78 | | - HELP |
| 94 | + puts "Options:" |
| 95 | + puts " -h, --help Show this help message" |
| 96 | + puts " -v, --version Show version" |
| 97 | + puts |
| 98 | + puts "Run 'git pkgs <command> -h' for command-specific options." |
79 | 99 | end |
80 | 100 | end |
81 | 101 | end |
|
0 commit comments