better args checking, sea list: cfg shown only on single items

This commit is contained in:
l_samenv
2021-12-06 11:54:19 +01:00
parent e7c1fce854
commit bb3c72acc9
3 changed files with 33 additions and 13 deletions

View File

@@ -50,6 +50,10 @@ class SewebManager(ServiceManager):
all = NicosManager, FrappyManager, SeaManager, SewebManager
ACTION = 1
INS = 2
SERVICE = 3
def run(group, arglist):
try:
@@ -59,19 +63,34 @@ def run(group, arglist):
serv = managers[group]
args = dict(action='gui', ins=serv.main_ins)
extra = []
pos = 0
unorder = False
for arg in arglist:
if hasattr(serv, 'do_' + arg):
args['action'] = arg
if pos >= ACTION:
unorder = True
pos = ACTION
elif arg in serv.services:
args['service'] = arg
elif arg in serv.info:
if pos >= SERVICE:
unorder = True
pos = SERVICE
elif arg in serv.info or arg == 'all':
args['ins'] = arg
if pos >= INS:
unorder = True
pos = INS
else:
extra.append(arg)
try:
serv.action(args['action'], *serv.treat_args(args, extra))
except AttributeError:
raise
if unorder:
print('do you mean:\n %s %s %s %s %s' %
(group, args.get('action', ''), args.get('ins', ''), args.get('service', ''), ' '.join(extra)))
else:
try:
serv.action(args['action'], *serv.treat_args(args, extra))
except AttributeError:
raise
except UsageError as e:
serv.do_help()
print('ERROR:', str(e))