hwylterm/tests/example.nim

75 lines
1.4 KiB
Nim
Raw Normal View History

2024-11-10 11:36:59 -06:00
import std/[strformat, strutils]
import hwylterm, hwylterm/hwylcli
2024-11-10 01:49:31 -06:00
2024-11-10 03:36:19 -06:00
type
Color = enum
red, blue, green
2024-11-10 11:36:59 -06:00
2024-11-10 01:49:31 -06:00
hwylCli:
name "example"
V "0.1.0"
... "a description of hwylterm"
flags:
2024-11-10 11:36:59 -06:00
[global]
2024-11-10 01:49:31 -06:00
yes:
T bool
? "set flag to yes"
2024-11-10 11:36:59 -06:00
[config]
confiG:
2024-11-10 01:49:31 -06:00
T seq[string]
? "path to config file"
* @["config.yml"]
2024-11-10 11:36:59 -06:00
preSub:
echo "this is run after subcommand parsing but before its run block"
2024-11-10 01:49:31 -06:00
run:
echo "this is always run prior to subcommand parsing"
subcommands:
2024-11-10 11:36:59 -06:00
--- "onelonger"
... """
the first subcommand
this command features both an enum flag and a Count flag
it also inherits the `[[config]` flag group
"""
2024-11-10 01:49:31 -06:00
flags:
2024-11-10 03:36:19 -06:00
color:
T Color
? "a color (red, green, blue)"
verbose:
T Count
? "a count flag"
- v
2024-11-10 11:36:59 -06:00
^[config]
2024-11-10 01:49:31 -06:00
run:
echo "hello from `example one` command!"
2024-11-10 03:36:19 -06:00
echo fmt"{color=}"
echo fmt"{verbose=}"
2024-11-10 11:36:59 -06:00
echo fmt"{config=}"
2024-11-10 01:49:31 -06:00
2024-11-10 11:36:59 -06:00
--- "two-longer"
2024-11-10 01:49:31 -06:00
... """
some second subcommand
a longer mulitline description that will be visible in the subcommand help
2024-11-10 11:36:59 -06:00
and it will automatically be "bb"'ed [bold]this is bold text[/]
2024-11-10 01:49:31 -06:00
"""
flags:
2024-11-10 11:36:59 -06:00
a:
2024-11-10 01:49:31 -06:00
T bool
? "some help"
2024-11-10 11:36:59 -06:00
b:
2024-11-10 01:49:31 -06:00
T seq[float]
? "multiple floats"
2024-11-10 11:36:59 -06:00
h "this will override the builtin 'h' for help"
2024-11-10 01:49:31 -06:00
run:
echo "hello from `example b` command"
2024-11-10 11:36:59 -06:00
echo fmt"{a=}, {b=}"
2024-11-10 01:49:31 -06:00