openloops.command_syntax#
Does each command of a run plan use only flags its program knows? (ADR-018)
A plan is checked before it is saved, so a step that would die on its first word
(unrecognized arguments: --trust) is caught by the planner, not by the owner at run
time. The check is cheap and read-only: for every simple command that passes long flags,
it asks the program for its help text (<program> [<subcommand>...] --help, no stdin,
pagers off, a short timeout) and reports the long flags the help never mentions.
It is a warning, not a proof. Help text that cannot be had (a program that does not
answer --help, BSD tools) is reported as such, and a program whose help omits some
flags gives false alarms; the planner reads each one. What it cannot see at all is a
requirement that depends on run-time state (“revive requires –cwd” when there is
nothing to resume): the runbook skill covers that by asking for every argument the
fallback path needs.
One seam: help_of=, (argv) -> str (empty when no help could be had), default
help_text().
Module Attributes
Shell builtins and small tools whose flags are not worth a |
|
Options a program takes before its subcommand, each with how many values follow it. |
|
Programs that run a script or module named next, whose own subcommands follow it. |
Functions
|
|
|
The |
|
The program and up to depth subcommand-looking words after it. |
|
Per simple command with long flags: the flags its help text never mentions. |
- openloops.command_syntax.LAUNCHERS = frozenset({'bun', 'deno', 'node', 'python', 'python3'})#
Programs that run a script or module named next, whose own subcommands follow it.
- openloops.command_syntax.LEAD_OPTIONS: dict[str, dict[str, int]] = {'gh': {'--repo': 1, '-R': 1}, 'git': {'--no-pager': 0, '-C': 1, '-P': 0, '-c': 1}}#
Options a program takes before its subcommand, each with how many values follow it.
- openloops.command_syntax.SKIP_PROGRAMS = frozenset({'.', '[', '[[', 'awk', 'basename', 'cat', 'cd', 'chmod', 'command', 'cp', 'cut', 'date', 'dirname', 'echo', 'env', 'eval', 'exec', 'exit', 'export', 'false', 'find', 'grep', 'head', 'ln', 'ls', 'mkdir', 'mv', 'printf', 'read', 'return', 'rmdir', 'sed', 'seq', 'set', 'shift', 'sleep', 'sort', 'source', 'stat', 'tail', 'tee', 'test', 'touch', 'tr', 'true', 'type', 'uniq', 'unset', 'wait', 'wc', 'xargs'})#
Shell builtins and small tools whose flags are not worth a
--helpround trip (and whose BSD versions answer--helpwith an error).
- openloops.command_syntax.help_text(argv, cwd=None, *, timeout=20.0)[source]#
argv --help’s output (run in cwd), or""when the program gives none (missing, an error without a usage line, a timeout, no option named) or when asking could run it (_answers_help()).- Return type:
- openloops.command_syntax.long_flags(words)[source]#
The
--longoptions in words (values after=dropped), in order, once each.>>> long_flags(['crowsnest', 'revive', 'x', '--trust', '--cwd=/a', '--', '--not']) ['--trust', '--cwd']
- openloops.command_syntax.subcommand_path(words, *, depth=2)[source]#
The program and up to depth subcommand-looking words after it.
>>> subcommand_path(['crowsnest', 'revive', 'yoga', '--trust']) ['crowsnest', 'revive', 'yoga'] >>> subcommand_path(['gh', 'issue', 'comment', '46', '-R', 'o/r']) ['gh', 'issue', 'comment'] >>> subcommand_path(['git', '-C', 'x', 'pull', '-q', '--ff-only']) ['git', 'pull'] >>> subcommand_path(['python', '-m', 'desk', 'pin-passkeys', '--name', 'jobs']) ['python', '-m', 'desk', 'pin-passkeys'] >>> subcommand_path(['python', 'deploy.py', 'cmd-deploy', '--app', 'x']) ['python', 'deploy.py', 'cmd-deploy']
- openloops.command_syntax.unknown_flags(command, *, cwd=None, help_of=<function help_text>, skip=frozenset({'.', '[', '[[', 'awk', 'basename', 'cat', 'cd', 'chmod', 'command', 'cp', 'cut', 'date', 'dirname', 'echo', 'env', 'eval', 'exec', 'exit', 'export', 'false', 'find', 'grep', 'head', 'ln', 'ls', 'mkdir', 'mv', 'printf', 'read', 'return', 'rmdir', 'sed', 'seq', 'set', 'shift', 'sleep', 'sort', 'source', 'stat', 'tail', 'tee', 'test', 'touch', 'tr', 'true', 'type', 'uniq', 'unset', 'wait', 'wc', 'xargs'}))[source]#
Per simple command with long flags: the flags its help text never mentions.
Help is asked in the folder the command would be in: cwd, then each
cd DIRmet along the way (acdto a computed path leaves the folder unknown).Each finding is
{"command": "<program subcommand>", "unknown": [...]}, or{"command": ..., "unknown": [], "no_help": True}when no help could be had.>>> helps = {('crowsnest', 'revive', 'yoga'): 'usage: revive [--cwd CWD] [--home HOME]'} >>> unknown_flags('crowsnest revive yoga --trust', help_of=lambda a, c: helps.get(tuple(a), '')) [{'command': 'crowsnest revive yoga', 'unknown': ['--trust']}] >>> unknown_flags('crowsnest revive yoga --cwd x', help_of=lambda a, c: helps.get(tuple(a), '')) [] >>> unknown_flags('cd ~/x && ls --color', help_of=lambda a, c: '') []