summaryrefslogtreecommitdiff
path: root/examples/modular_commands/commandset_custominit.py
blob: d96c5f1c6366b044fc34760977bb7823a9d6139b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding=utf-8
"""
A simple example demonstrating a loadable command set
"""
from cmd2 import Cmd, CommandSet, Statement, register_command, with_category, with_default_category


@register_command
@with_category("AAA")
def do_another_command(cmd: Cmd, statement: Statement):
    """
    This is an example of registering an unbound function
    :param cmd:
    :param statement:
    :return:
    """
    cmd.poutput('Another Unbound Command: {}'.format(statement.args))


@with_default_category('Custom Init')
class CustomInitCommandSet(CommandSet):
    def __init__(self, arg1, arg2):
        super().__init__()

        self._arg1 = arg1
        self._arg2 = arg2

    def do_show_arg1(self, cmd: Cmd, _: Statement):
        cmd.poutput('Arg1: ' + self._arg1)

    def do_show_arg2(self, cmd: Cmd, _: Statement):
        cmd.poutput('Arg2: ' + self._arg2)