xotl.tools.cli
– Command line application facilities¶
Applications¶
Tools¶
Utilities for command-line interface (CLI) applications.
program_name()
: calculate the program name from “sys.argv[0]”.command_name()
\ : calculate command names using class names in lower- case inserting a hyphen before each new capital letter.
-
xotl.tools.cli.tools.
command_name
(cls)[source]¶ Calculate a command name from given class.
Names are calculated putting class names in lower case and inserting hyphens before each new capital letter. For example “MyCommand” will generate “my-command”.
It’s defined as an external function because a class method don’t apply to minimal commands (those with only the “run” method).
Example:
>>> class SomeCommand: ... pass >>> command_name(SomeCommand) == 'some-command' True
If the command class has an attribute command_cli_name, this will be used instead:
>>> class SomeCommand: ... command_cli_name = 'adduser' >>> command_name(SomeCommand) == 'adduser' True
It’s an error to have a non-string command_cli_name attribute:
>>> class SomeCommand: ... command_cli_name = None >>> command_name(SomeCommand) Traceback (most recent call last): ... TypeError: Attribute 'command_cli_name' must be a string.
-
xotl.tools.cli.tools.
hyphen_name
(name, join_numbers=True)[source]¶ Convert a name to a hyphened slug.
Expects a name in Camel-Case. All invalid characters (those invalid in Python identifiers) are ignored. Numbers are joined with preceding part when join_numbers is True.
For example:
>>> hyphen_name('BaseNode') == 'base-node' True >> hyphen_name('--__ICQNámeP12_34Abc--') == 'icq-name-p12-34-abc' True >> hyphen_name('ICQNámeP12', join_numbers=False) == 'icq-name-p-12' True