simplify bbansi help generation

This commit is contained in:
Daylin Morgan 2024-09-25 14:21:42 -05:00
parent 38b1854c12
commit 5ee8117e96
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -176,9 +176,17 @@ when isMainModule:
import std/[parseopt, strformat, sugar] import std/[parseopt, strformat, sugar]
const version = staticExec "git describe --tags --always --dirty=-dev" const version = staticExec "git describe --tags --always --dirty=-dev"
const longOptPad = 8 const longOptPad = 8
const flags = collect(
for (s, l, d) in [
("h", "help", "show this help"),
("v", "version", "show version"),
("s", "style", "set style for string"),
]:
fmt" [yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}"
).join("\n")
proc writeHelp() = proc writeHelp() =
let help = let help =
fmt""" bbfmt"""
[bold]bbansi[/] \[[green]args...[/]] [[[faint]-h|-v[/]] [bold]bbansi[/] \[[green]args...[/]] [[[faint]-h|-v[/]]
[italic]usage[/]: [italic]usage[/]:
@ -190,22 +198,9 @@ when isMainModule:
|-> [italic][red]some red[/red] but all italic[/italic] |-> [italic][red]some red[/red] but all italic[/italic]
flags: flags:
""".bb & {flags}
$( """
bb( echo help; quit 0
collect(
for (s, l, d) in [
("h", "help", "show this help"),
("v", "version", "show version"),
("s", "style", "set style for string"),
]:
fmt"[yellow]-{s}[/] [green]--{l.alignLeft(longOptPad)}[/] {d}"
)
.join("\n ")
)
)
echo help
quit(QuitSuccess)
proc testCard() = proc testCard() =
for style in [ for style in [
@ -228,8 +223,8 @@ flags:
echo ")" echo ")"
proc writeVersion() = proc writeVersion() =
echo fmt"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]".bb echo bbfmt"[yellow]bbansi version[/][red] ->[/] [bold]{version}[/]"
quit(QuitSuccess) quit 0
var var
strArgs: seq[string] strArgs: seq[string]