Skip to content

Commit d4bad79

Browse files
committed
fix command line parsing
1 parent b1b7be5 commit d4bad79

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

doorsh.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@
88
class DoorShell(cmd.Cmd):
99
prompt = 'doorbot> '
1010

11+
def get_args(self, line):
12+
return [ x for x in line.split(' ') if x != '' ]
13+
1114
def __init__(self):
1215
cmd.Cmd.__init__(self)
1316

14-
def do_list(self, arg):
17+
def do_list(self, line):
1518
"""list"""
1619
doorctl.list_users()
1720

18-
def do_enable(self, arg):
21+
def do_enable(self, line):
1922
"""enable <fobid>"""
20-
for rfid in arg.strip(' ').rstrip(' ').split(' '):
23+
for rfid in self.get_args(line):
2124
doorctl.enable(rfid)
2225

23-
def do_disable(self, arg):
26+
def do_disable(self, line):
2427
"""disable <fobid>"""
25-
for rfid in arg.strip(' ').rstrip(' ').split(' '):
28+
for rfid in self.get_args(line):
2629
doorctl.disable(rfid)
2730

28-
def do_delete(self, arg):
31+
def do_delete(self, line):
2932
"""delete <fobid>"""
30-
for rfid in arg.strip(' ').rstrip(' ').split(' '):
33+
for rfid in self.get_args(line):
3134
doorctl.delete(rfid)
3235

33-
def do_addkey(self, arg):
36+
def do_addkey(self, line):
3437
"""addkey [<fobid> <pin>]"""
35-
args = arg.strip(' ').rstrip(' ').split(' ')
36-
if args[0] == '':
38+
args = self.get_args(line)
39+
if len(args) == 0:
3740
doorctl.socket_command('addkey')
3841
elif len(args) == 2:
3942
try:
@@ -44,18 +47,18 @@ def do_addkey(self, arg):
4447
else:
4548
print "usage: addkey [<fobid> <pin>]"
4649

47-
def do_openmode(self, arg):
50+
def do_openmode(self, line):
4851
"""openmode"""
4952
doorctl.socket_command('openmode')
5053

51-
def do_authmode(self, arg):
54+
def do_authmode(self, line):
5255
"""authmode"""
5356
doorctl.socket_command('authmode')
5457

55-
def do_resetpin(self, arg):
58+
def do_resetpin(self, line):
5659
"""resetpin [<fobid> <pin>]"""
57-
args = arg.strip(' ').rstrip(' ').split(' ')
58-
if args[0] == '':
60+
args = self.get_args(line)
61+
if len(args) == 0:
5962
doorctl.socket_command('resetpin')
6063
elif len(args) == 2:
6164
try:
@@ -66,19 +69,19 @@ def do_resetpin(self, arg):
6669
else:
6770
print "usage: resetpin [<fobid> <pin>]"
6871

69-
def do_shutdown(self, arg):
72+
def do_shutdown(self, line):
7073
"""shutdown"""
7174
doorctl.socket_command('shutdown')
7275

73-
def do_restart(self, arg):
76+
def do_restart(self, line):
7477
"""restart"""
7578
doorctl.socket_command('restart')
7679

77-
def do_quit(self, arg):
80+
def do_quit(self, line):
7881
"""quit"""
7982
sys.exit(0)
8083

81-
def do_EOF(self, arg):
84+
def do_EOF(self, line):
8285
"""quit"""
8386
sys.exit(0)
8487

0 commit comments

Comments
 (0)