aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/commands/help.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/commands/help.py')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/commands/help.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/commands/help.py b/packages/meshbay-cli/src/meshbay_cli/commands/help.py
new file mode 100644
index 0000000..6515800
--- /dev/null
+++ b/packages/meshbay-cli/src/meshbay_cli/commands/help.py
@@ -0,0 +1,27 @@
+"""`help`: what `--help` prints, for the program or for one action."""
+
+from ..errors import USAGE, CliError
+from ..output import sentence
+from .context import Context
+
+HELP = "what --help prints: the actions, or one action's options"
+
+
+def add_parser(sub, parent) -> None:
+ p = sub.add_parser("help", parents=[parent], help=HELP, description=sentence(HELP) + ".")
+ p.add_argument("topic", nargs="?", metavar="ACTION", help="the action to explain")
+
+
+async def run(ctx: Context) -> int:
+ from ..__main__ import build_parser
+ parser = build_parser()
+ topic = ctx.args.topic
+ if topic is None:
+ parser.print_help()
+ return 0
+ actions = next(a for a in parser._actions if hasattr(a, "choices") and a.choices
+ and "help" in a.choices).choices
+ if topic not in actions:
+ raise CliError(USAGE, f"No action {topic!r}. The actions: {', '.join(actions)}.")
+ actions[topic].print_help()
+ return 0