-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.py
56 lines (49 loc) · 1.69 KB
/
command.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import cmd
import parsers
from equalizer import Equalizer
class Command(cmd.Cmd):
intro = 'Welcome to the expenses equalizer shell. Type help or ? to list commands.\n'
prompt = '[exp_eq] '
file = None
eq = Equalizer()
def do_member(self, arg):
try:
args = parsers.member_parser.parse_args(arg.split())
except Exception as exc :
print(exc)
return
print(f"in member command! args: {arg}")
if args.cmd == 'add':
print(f"Creating new member: {args.new_member}")
self.eq.add_member(args.new_member)
def do_exp(self, arg):
try:
args = parsers.exp_parser.parse_args(arg.split())
except Exception as exc :
print(exc)
return
print(f"in expenses command! args: {arg}")
if args.cmd == 'load':
print('in load command')
if args.f:
print('load from file')
self.eq.load_spreadsheet(args.f)
if args.u:
print('load from url')
def do_exit(self, arg):
print('Thank you for using Expenses Equalizer.')
return True
def precmd(self, line:str):
if not (line.startswith('exp load') or len(line) == 0):
if not self.check_spreadsheet():
return ""
return line
def check_spreadsheet(self):
if not self.eq.is_spreadsheet_loaded():
ans = input(
"No spreadsheet loaded. Do you want to initialize new one? [y/n]")
if ans.lower() == 'y':
self.eq.init_spreadsheet()
return True
else: return False
else: return True