Skip to content

Commit dbde247

Browse files
Tidied up subcommand help formatting
1 parent 6cd2eb9 commit dbde247

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/arca_cli.ex

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,8 @@ defmodule Arca.Cli do
12481248
_ -> true
12491249
end
12501250

1251-
# Format the command list
1252-
command_list =
1251+
# Get command names and descriptions
1252+
commands_with_descriptions =
12531253
visible_commands
12541254
|> Enum.map(fn module ->
12551255
{cmd_atom, opts} = apply(module, :config, []) |> List.first()
@@ -1259,8 +1259,21 @@ defmodule Arca.Cli do
12591259
end)
12601260
# Sort by name (alphabetically) if sorting is enabled
12611261
|> maybe_sort_commands(should_sort)
1262+
1263+
# Calculate the maximum command name length to ensure proper alignment
1264+
max_name_length =
1265+
commands_with_descriptions
1266+
|> Enum.map(fn {name, _} -> String.length(name) end)
1267+
|> Enum.max(fn -> 0 end)
1268+
1269+
# Add 2 spaces of padding after the longest command name
1270+
padding_width = max_name_length + 2
1271+
1272+
# Format the command list with dynamic padding
1273+
command_list =
1274+
commands_with_descriptions
12621275
|> Enum.map(fn {name, about} ->
1263-
padding = String.duplicate(" ", max(0, 20 - String.length(name)))
1276+
padding = String.duplicate(" ", max(0, padding_width - String.length(name)))
12641277
" #{name}#{padding}#{about}"
12651278
end)
12661279

0 commit comments

Comments
 (0)