improve missing arg handling

- better error messages
- missing instrument is only allowed with 'list'
- missing argument to be replaced with ? in error message
- sea cli may now be given with 'graph' or 'sea' for service
This commit is contained in:
l_samenv
2025-01-21 10:49:54 +01:00
parent fda6e37238
commit 556a7eff9d
3 changed files with 23 additions and 15 deletions

View File

@@ -49,7 +49,7 @@ class SewebManager(ServiceManager):
all = NicosManager, FrappyManager, SeaManager, SewebManager
KINDS = 'action', 'ins', 'service'
def run(group, arglist):
try:
@@ -68,7 +68,7 @@ def run(group, arglist):
'service': lambda arg: arg in serv.services,
}
for kind in 'action', 'ins', 'service':
for kind in KINDS:
if arglist and arg_is[kind](arglist[0]): # arg is of expected kind
args[kind] = arglist.pop(0)
continue
@@ -91,8 +91,11 @@ def run(group, arglist):
args.setdefault('ins', serv.main_ins)
if guessed_args:
args.setdefault('action', 'gui')
print('do you mean:\n %s %s %s %s %s' %
(group, args.get('action', ''), args.get('ins', ''), args.get('service', ''), ' '.join(extra)))
guessed = [group] + [args.get(k, '') for k in KINDS] + extra
while not guessed[-1]:
guessed.pop()
guessed = ' '.join(a or '?' for a in guessed)
print(f'do you mean:\n {guessed}')
else:
try:
serv.action(args['action'], *serv.treat_args(args, extra + arglist))