Use argparse
This commit is contained in:
parent
b43c7bae97
commit
110297ffb8
23
eufy.py
23
eufy.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import cmd
|
||||
from cmd import Cmd
|
||||
from datetime import datetime, time
|
||||
from inspect import getargspec
|
||||
from shlex import shlex
|
||||
|
@ -143,7 +143,7 @@ def lexer(f):
|
|||
return g
|
||||
|
||||
|
||||
class Eufy(cmd.Cmd):
|
||||
class Eufy(Cmd):
|
||||
|
||||
prompt = 'eufy> '
|
||||
|
||||
|
@ -215,9 +215,22 @@ class Eufy(cmd.Cmd):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from argparse import ArgumentParser, FileType
|
||||
|
||||
parser = ArgumentParser(description='Eufy RoboVac 11s CLI tool')
|
||||
parser.add_argument('-f', '--file', type=FileType('r'), help='read commands from file')
|
||||
parser.add_argument('command', nargs='*')
|
||||
args = parser.parse_args()
|
||||
|
||||
eufy = Eufy()
|
||||
if len(sys.argv) > 1:
|
||||
eufy.cmdqueue = ' '.join(sys.argv[1:]).split(',') + ['quit']
|
||||
|
||||
if args.file:
|
||||
eufy.cmdqueue.extend(args.file.readlines())
|
||||
|
||||
if args.command:
|
||||
eufy.cmdqueue.extend(' '.join(args.command).split(','))
|
||||
|
||||
if eufy.cmdqueue:
|
||||
eufy.cmdqueue.append('quit')
|
||||
|
||||
eufy.cmdloop()
|
||||
|
|
Loading…
Reference in New Issue