pytest_mh.cli
Classes
|
- class pytest_mh.cli.CLIBuilder(shell: Shell)
Bases:
object- Parameters:
shell (Shell) – Target shell.
- class option(value)
Bases:
EnumCommand line parameter types.
- PLAIN = 1
Use plain parameter value without any modification.
- VALUE = 2
Use parameter value but enclose it in quotes in script mode.
- SWITCH = 3
Parameter is a switch which is enabled if value is True.
- POSITIONAL = 4
Parameter is a positional argument.
- command(command: str, args: dict[str, tuple[option, Any] | None]) str
Build full command line and return it as a string.
Output can be passed directly to
Connection.run(host.conn.run).Examplecli = CLIBuilder(Bash()) args: CLIBuilderArgs = { "password": (cli.option.VALUE, None), # None values are ignored "home": (cli.option.VALUE, "/home/jdoe"), # --home '/home/jdoe' "enabled": (cli.option.SWITCH, True), # --enabled "login": (cli.option.POSITIONAL, "jdoe"), # 'jdoe' } line = cli.command("add-user", args) # add-user --home '/home/jdoe' --enabled 'jdoe'
- argv(command: str, args: dict[str, tuple[option, Any] | None]) list[str]
Build full command line and return it it as list of arguments (full argv).
Output can be passed directly to
Connection.exec(host.conn.exec).Examplecli = CLIBuilder(Bash()) args: CLIBuilderArgs = { "password": (cli.option.VALUE, None), # None values are ignored "home": (cli.option.VALUE, "/home/jdoe"), # --home '/home/jdoe' "enabled": (cli.option.SWITCH, True), # --enabled "login": (cli.option.POSITIONAL, "jdoe"), # 'jdoe' } line = cli.argv("add-user", args) # ["add-user", "--home", "/home/jdoe", "--enabled", "jdoe"]
- args(args: dict[str, tuple[option, Any] | None], *, quote_value=False) list[str]
Build command’s arguments and return them as a list (argv without command).
Output can be used for additional processing by the caller.
Examplecli = CLIBuilder(Bash()) args: CLIBuilderArgs = { "password": (cli.option.VALUE, None), # None values are ignored "home": (cli.option.VALUE, "/home/jdoe"), # --home '/home/jdoe' "enabled": (cli.option.SWITCH, True), # --enabled "login": (cli.option.POSITIONAL, "jdoe"), # 'jdoe' } line = cli.args(args) # ["--home", "/home/jdoe", "--enabled", "jdoe"] host.conn.run(f"user-add --encrypt-home {' '.join(line)}")