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 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"
|
2024-11-12 14:20:16 -06:00
|
|
|
[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
|
2024-11-12 14:20:16 -06:00
|
|
|
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
|
2024-11-12 14:20:16 -06:00
|
|
|
^[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:
|
2024-11-12 14:20:16 -06:00
|
|
|
^something
|
2024-11-17 12:24:39 -06:00
|
|
|
thing:
|
2024-11-19 14:39:27 -06:00
|
|
|
T seq[KV[string, Color]]
|
|
|
|
? "some key value colors"
|
2024-11-10 11:36:59 -06:00
|
|
|
b:
|
2024-11-10 01:49:31 -06:00
|
|
|
T seq[float]
|
|
|
|
? "multiple floats"
|
2024-11-18 14:52:43 -06:00
|
|
|
def:
|
2024-11-19 14:39:27 -06:00
|
|
|
T string
|
2024-11-18 14:52:43 -06:00
|
|
|
? "a flag with a string default"
|
|
|
|
* "the value"
|
2024-11-10 01:49:31 -06:00
|
|
|
run:
|
|
|
|
echo "hello from `example b` command"
|
2024-11-19 14:39:27 -06:00
|
|
|
echo fmt"{thing=}, {b=}, {def=}"
|
2024-11-10 01:49:31 -06:00
|
|
|
|