The node handler

When you want to do something (eg prints current version) but don’t want to add a command for it. For example cli -v

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from command_tree import CommandTree

tree = CommandTree()

@tree.optional
@tree.root()
@tree.argument('-v', action = 'store_true')
class Root(object):

    def __init__(self, version):
        pass

    @tree.leaf()
    def command1(self):
        return "1"

    @tree.node_handler
    def handler(self, version):
        if version:
            return "42.0"

print(tree.execute())