hwylterm/tests/example.nim

86 lines
1.7 KiB
Nim
Raw Permalink 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"
flags:
2024-11-10 11:36:59 -06:00
[global]
2024-11-13 11:29:09 -06:00
color:
T Color
? "a color (red, green, blue)"
2024-11-10 01:49:31 -06:00
yes:
T bool
? "set flag to yes"
[shared]
something:
? "some flag only needed in one subcommand"
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-13 11:29:09 -06:00
echo fmt"{yes=}, {color=}"
2024-11-10 01:49:31 -06:00
run:
echo "this is always run prior to subcommand parsing"
2024-11-13 11:29:09 -06:00
echo fmt"{yes=}, {color=}"
2024-11-10 01:49:31 -06:00
subcommands:
2024-11-13 11:29:09 -06:00
[one]
2024-11-14 14:36:53 -06:00
help:
description """
2024-11-10 11:36:59 -06:00
the first subcommand
this command features both an enum flag and a Count flag
it also inherits the `[[shared]` flag group
2024-11-10 11:36:59 -06:00
"""
2024-11-13 11:29:09 -06:00
alias o
2024-11-10 01:49:31 -06:00
flags:
2024-11-10 03:36:19 -06:00
verbose:
T Count
? "a count flag"
- v
^[shared]
2024-11-13 09:07:54 -06:00
subcommands:
[subsub]
... "another level down subcommand"
flags:
2024-11-13 11:29:09 -06:00
^config
2024-11-13 09:07:54 -06:00
run:
echo fmt"{color=}"
2024-11-13 11:29:09 -06:00
2024-11-10 01:49:31 -06:00
run:
echo "hello from `example one` command!"
2024-11-10 16:19:44 -06:00
echo args
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-13 11:29:09 -06:00
[two]
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:
^something
auto:
- a
2024-11-10 01:49:31 -06:00
? "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"
echo fmt"{auto=}, {b=}"
2024-11-10 01:49:31 -06:00