summaryrefslogtreecommitdiff
path: root/src/arg_parser.py
blob: a5fdb40bcb47e4da941d5c6420faa884e01a6588 (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
import argparse
import sys


AVAILABLE_COMMANDS_HELP_STRING = """Available commands:
                                    row-at n: print row at the nth position
                                    get-rows n: print first n rows
                                    insert "csv string": insert row at the end, the row must have exactly 3 elements.
                                    search "lookup": search "lookup" in the table.
                                    delete-at n: delete row at nth position
                                 """


class ArgParser:
    def __init__(self, args=sys.argv):
        self.parser = argparse.ArgumentParser()
        self.parser.add_argument('-f', required=True, help='CSV file location')
        self.parser.add_argument('-c', required=True, help=AVAILABLE_COMMANDS_HELP_STRING, nargs=2)
        self.args = self.parser.parse_args(args)

    @property
    def file(self):
        return self.args.f

    @property
    def command(self):
        return self.args.c

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