aboutsummaryrefslogtreecommitdiff
path: root/scripts/lesana
blob: b8b9929b79ba193ee4fcf26e01fefa8b780f3781 (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
33
34
35
36
37
38
39
40
#!/usr/bin/env python3

import argparse

from lesana.command import New, Edit, Show, Index, Search, Init, Remove

class Lesana():
    """
    Manage collections
    """

    commands = (
        ('new', New()),
        ('edit', Edit()),
        ('show', Show()),
        ('index', Index()),
        ('search', Search()),
        ('init', Init()),
        ('rm', Remove()),
        )

    def _main(self):
        self.parser.print_help()

    def main(self):
        self.parser = argparse.ArgumentParser()
        self.parser.set_defaults(func=self._main)
        self.subparsers = self.parser.add_subparsers()
        for name, sub in self.commands:
            s_parser = self.subparsers.add_parser(name, help=sub.help)
            for arg in sub.arguments:
                s_parser.add_argument(*arg[0], **arg[1])
            s_parser.set_defaults(func=sub._main)
        self.args = self.parser.parse_args()
        self.args.func(self.args)



if __name__ == '__main__':
    Lesana().main()