mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-11-16 06:28:32 -06:00
simplify help output
This commit is contained in:
parent
b6202f4f51
commit
e964581b13
1 changed files with 10 additions and 14 deletions
|
@ -11,9 +11,9 @@ import ./[bbansi, parseopt3]
|
||||||
export parseopt3
|
export parseopt3
|
||||||
|
|
||||||
type
|
type
|
||||||
HwylFlagHelp = tuple
|
HwylFlagHelp* = tuple
|
||||||
short, long, description: string
|
short, long, description: string
|
||||||
HwylSubCmdHelp = tuple
|
HwylSubCmdHelp* = tuple
|
||||||
name, desc: string
|
name, desc: string
|
||||||
HwylCliStyles* = object
|
HwylCliStyles* = object
|
||||||
hdr = "bold cyan"
|
hdr = "bold cyan"
|
||||||
|
@ -22,7 +22,6 @@ type
|
||||||
descFlag = ""
|
descFlag = ""
|
||||||
cmd = "bold"
|
cmd = "bold"
|
||||||
HwylCliHelp* = object
|
HwylCliHelp* = object
|
||||||
cmd*: string
|
|
||||||
usage*: string
|
usage*: string
|
||||||
desc*: string
|
desc*: string
|
||||||
subcmds: seq[HwylSubCmdHelp]
|
subcmds: seq[HwylSubCmdHelp]
|
||||||
|
@ -30,18 +29,19 @@ type
|
||||||
styles*: HwylCliStyles
|
styles*: HwylCliStyles
|
||||||
subcmdLen, subcmdDescLen, shortArgLen, longArgLen, descArgLen: int
|
subcmdLen, subcmdDescLen, shortArgLen, longArgLen, descArgLen: int
|
||||||
|
|
||||||
|
# NOTE: do i need both strips?
|
||||||
|
func firstLine(s: string): string =
|
||||||
|
s.strip().dedent().strip().splitlines()[0]
|
||||||
func newHwylCliHelp*(
|
func newHwylCliHelp*(
|
||||||
cmd = "",
|
|
||||||
usage = "",
|
usage = "",
|
||||||
desc = "",
|
desc = "",
|
||||||
subcmds: openArray[HwylSubCmdHelp] = @[],
|
subcmds: openArray[HwylSubCmdHelp] = @[],
|
||||||
flags: openArray[HwylFlagHelp] = @[],
|
flags: openArray[HwylFlagHelp] = @[],
|
||||||
styles = HwylCliStyles()
|
styles = HwylCliStyles()
|
||||||
): HwylCliHelp =
|
): HwylCliHelp =
|
||||||
result.cmd = cmd
|
|
||||||
result.desc = dedent(desc).strip()
|
result.desc = dedent(desc).strip()
|
||||||
result.subcmds = subcmds.mapIt((it.name,it.desc.strip().dedent().strip().splitlines()[0]))
|
result.subcmds =
|
||||||
|
subcmds.mapIt((it.name, it.desc.firstLine))
|
||||||
result.usage = dedent(usage).strip()
|
result.usage = dedent(usage).strip()
|
||||||
result.flags = @flags
|
result.flags = @flags
|
||||||
result.styles = styles
|
result.styles = styles
|
||||||
|
@ -90,16 +90,13 @@ func subCmdLine(cli: HwylCliHelp, subcmd: HwylSubCmdHelp): string =
|
||||||
result.add "\n"
|
result.add "\n"
|
||||||
|
|
||||||
proc bbImpl(cli: HwylCliHelp): string =
|
proc bbImpl(cli: HwylCliHelp): string =
|
||||||
if cli.cmd != "":
|
|
||||||
result.add cli.cmd
|
|
||||||
result.add "\n"
|
|
||||||
if cli.usage != "":
|
if cli.usage != "":
|
||||||
result.add "\n"
|
|
||||||
result.add "[" & cli.styles.hdr & "]"
|
result.add "[" & cli.styles.hdr & "]"
|
||||||
result.add "usage[/]:\n"
|
result.add "usage[/]:\n"
|
||||||
result.add indent(cli.usage, 2 )
|
result.add indent(cli.usage, 2 )
|
||||||
|
result.add "\n"
|
||||||
if cli.desc != "":
|
if cli.desc != "":
|
||||||
result.add "\n\n"
|
result.add "\n"
|
||||||
result.add cli.desc
|
result.add cli.desc
|
||||||
result.add "\n"
|
result.add "\n"
|
||||||
if cli.subcmds.len > 0:
|
if cli.subcmds.len > 0:
|
||||||
|
@ -437,7 +434,7 @@ func defaultUsage(cfg: CliCfg): NimNode =
|
||||||
|
|
||||||
func generateCliHelperProc(cfg: CliCfg, printHelpName: NimNode): NimNode =
|
func generateCliHelperProc(cfg: CliCfg, printHelpName: NimNode): NimNode =
|
||||||
let
|
let
|
||||||
name = newLit(cfg.name)
|
# name = newLit(cfg.name)
|
||||||
desc = cfg.desc or newLit("")
|
desc = cfg.desc or newLit("")
|
||||||
usage = cfg.usage or defaultUsage(cfg)
|
usage = cfg.usage or defaultUsage(cfg)
|
||||||
helpFlags = cfg.flagsArray()
|
helpFlags = cfg.flagsArray()
|
||||||
|
@ -447,7 +444,6 @@ func generateCliHelperProc(cfg: CliCfg, printHelpName: NimNode): NimNode =
|
||||||
result = quote do:
|
result = quote do:
|
||||||
proc `printHelpName`() =
|
proc `printHelpName`() =
|
||||||
echo newHwylCliHelp(
|
echo newHwylCliHelp(
|
||||||
cmd = `name`,
|
|
||||||
desc = `desc`,
|
desc = `desc`,
|
||||||
usage = `usage`,
|
usage = `usage`,
|
||||||
subcmds = `subcmds`,
|
subcmds = `subcmds`,
|
||||||
|
|
Loading…
Reference in a new issue