Skip to content

Top Level Command

The top-level command is a module with an identically named function in it. It is similar to a package as a feature, except it is a module, not a package. I.E it is a module as a feature with an identically named function in it.

Let's create sample one:

$ touch storage_X/cli/dev/destroy.py

Define the command as:

destroy.py
def destroy(name: str) -> None:
    """
    Destroy given name...(top-level command)

    Args:

        name (str): Name of project

    Return: None
    """
    print(f"This is a top level destroyer - {name}")

Get the help message:

$ ./awesome -h
usage: awesome [-h] {destroy,service,upload,environment} ...

positional arguments:
  {destroy,service,upload,environment}
    destroy             Destroy given name...(top-level command) # (1)
    service             The service feature to handle our services # (2)
    upload              This is an example of module feature # (3)
    environment         The environment feature to handle our environments # (4)

optional arguments:
  -h, --help            show this help message and exit
  1. Top-level command from storage_X
  2. Package as a feature from storage_X
  3. Module as a feature from storage_X
  4. Package as a feature from storage_Y

Get the top-level command help:

$ ./awesome destroy -h
usage: awesome destroy [-h] name

positional arguments:
  name        Name of project

optional arguments:
  -h, --help  show this help message and exit

Run the top-level command:

$ ./awesome destroy please
This is a top-level destroyer - please

Versioning

You can add a unique version to your top level command by adding __version__:

destroy.py
__version__ = "1.1a1"

def destroy(name: str) -> None:

Get the version information:

./awesome destroy -h
usage: awesome destroy [-h] [-v] name

positional arguments:
  name           Name of project

optional arguments:
  -h, --help     show this help message and exit
  -v, --version  show program's version number and exit
$ ./awesome destroy --version
awesome destroy - v1.1a1