Command

class ezcliy.commands.Command

Base class for creating commands. You probably will override this class

description: str = None

Description for help

values: list = []

Cleaned values from cmd

require_all_defined_positionals = False

If true, allow only values referenced as positionals

none_args_will_not_trigger_help = True

If true, will not print help when command is issued without parameters

name: str = None

Name of command

property commands: dict
Returns

Subcommands

property is_subcommand_issued
Returns

True if subcommand has been issued

Return type

bool

property parameters: dict
Returns

All declared parameters as name-parameter dict

Return type

dict[str, Parameter]

property positionals
Returns

All declared positionals

Return type

list[Positional]

dispatch(args: list)

The magic spaghetti of framework.

Parameters

args – list of arguments to process

invoke() Optional[Any]

The entry point for your command. Can return values while being called by entry or cli_entry.

entry(*args: str)

Handles errors caused by dispatch method. Used also for testing. Use it on dev env.

Parameters

args (str) – list of passed arguments

cli_entry()

This method grabs args from terminal. You should put it into if main. This should be used in production.

Subcommands

Ez cliy allows to create subcommands.

from ezcliy import *


class Parent(Command):
    a = Flag('-a')

    class ChildA(Command):
        name = 'cha'  # Subcommands must have names
        a: Flag  # That will got "a" param from parent

        def invoke(self):
            print(f'My name is {self.name} and my parent gave me param {self.a}')

    class CardiB(Command):
        name = 'cab'
        b = Flag('-b')

        class Kanye(Command):  # No level limits
            name = 'kanye'
            c = Flag('-c')

            def invoke(self):
                print('oh kanye')

        def invoke(self):
            print(f'I don\'t have my parent\'s param so i referenced my own {self.b}')

    def invoke(self):
        print('even, still i have children, i can be invoked')
        if not self.is_subcommand_issued:
            print('as we can see, i\'m still worthy')


if __name__ == '__main__':
    Parent().cli_entry()

Help

Ez cliy has built-in help generator. It can be invoked by typing --help. Also it will executed when command has no arguments or values.

Tip

You can change that behaviour by setting Command.none_args_will_not_trigger_help on True