Skip to content

Commit

Permalink
refactor app help description wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed Jun 11, 2024
1 parent bec267b commit 118cfa8
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/glint.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,15 @@ fn app_help_to_string(help: AppHelp) -> String {
s -> "Command: " <> s
}

let command_description =
help.command.meta.description
|> utils.wordwrap(help.config.max_output_width)
|> string.join("\n")

[
option.unwrap(help.config.description, ""),
command,
string.join(
utils.wordwrap(
help.command.meta.description,
help.config.max_output_width,
),
"\n",
),
command_description,
command_help_to_usage_string(help.command, help.config),
flags_help_to_string(help.command.flags, help.config),
subcommands_help_to_string(help.command.subcommands, help.config),
Expand Down Expand Up @@ -867,19 +866,20 @@ fn command_help_to_usage_string(help: CommandHelp, config: Config) -> String {
// The max width of the usage accounts for the constant indent
let max_usage_width = config.max_output_width - config.indent_width

case config.pretty_help {
None -> usage_heading
Some(pretty) -> heading_style(usage_heading, pretty.usage)
}
<> "\n"
<> string.repeat(" ", config.indent_width)
<> {
let content =
[app_name, help.meta.name, subcommands, named_args, unnamed_args, flags]
|> list.filter(is_not_empty)
|> string.join(" ")
|> utils.wordwrap(max_usage_width)
|> string.join("\n" <> string.repeat(" ", config.indent_width * 2))

case config.pretty_help {
None -> usage_heading
Some(pretty) -> heading_style(usage_heading, pretty.usage)
}
<> "\n"
<> string.repeat(" ", config.indent_width)
<> content
}

// -- HELP - FUNCTIONS - STRINGIFIERS - FLAGS --
Expand Down

0 comments on commit 118cfa8

Please sign in to comment.