Documentation

cli

Command-line argument parsing utilities for Context-Fabric tools.

This module provides a flexible argument parser for CLI tools that need to handle tasks, parameters, and flags. It supports:

- Named tasks with descriptions - Key=value parameters with defaults - Boolean and tri-state flags (-/+/++ syntax) - Automatic help text generation - Validation of argument names

See Also -------- readArgs : Main function for parsing command-line arguments

Functions

function
readArgs(command: str, descr: str, possibleTasks: dict[(str, str)], possibleParams: dict[(str, tuple[(str, str)])], possibleFlags: dict[(str, tuple[(str, int | bool, int)])], notInAll: set[str] = {'arguments': [], 'cls': 'ExprCall', 'function': {'cls': 'ExprName', 'member': None, 'name': 'set'}}) tuple[(bool, dict[(str, bool)], dict[(str, str)], dict[(str, int | bool)])]

Interpret tasks, parameters and flags specified.

Interpret tasks, parameters and flags specified. Parameters ---------- command: The name of the command, as entered on the command-line descr: string A description of the task possibleTasks: dict Keyed by the names of tasks, the values are a short description of the task. possibleParams: dict Keyed by the names of the parameters, the values are tuples with a short description of the parameter plus a default value for it. possibleFlags: dict Keyed by the name of the flags, the values are tuples with a short description of the flag, plus a default value for it, plus the number of values it can take. There are these possibilities: * `2`: values are False or True, represented by `-` and `+`; * `3`: values are `-1`, `0` or `1`, represented by `-`, `+` and `++`. notInAll: set, optional set() A set of tasks which are excluded from execution if `all` is passed as a task argument. Such tasks will only by executed if they are explicitly passed as an argument to the command. Returns ------- tuple The tuple returned consists of * a boolean whether there is an error in the arguments * a dict keyed by the tasks, values are True or False * a dict of the parameters, values are strings * a dict of the flags, values are -1, 0 or 1
Parameters
  • command: str
  • descr: str
  • possibleTasks: dict[(str, str)]
  • possibleParams: dict[(str, tuple[(str, str)])]
  • possibleFlags: dict[(str, tuple[(str, int | bool, int)])]
  • notInAll: set[str]