41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/confctl/cli/command.rb', line 41
def require_args!(*required, optional: [], strict: true)
if args.count < required.count
arg = required[args.count]
raise GLI::BadCommandLine, "missing argument <#{arg}>"
elsif strict && args.count > (required.count + optional.count)
unknown = args[(required.count + optional.count)..]
msg = ''
msg << if unknown.count > 1
'unknown arguments: '
else
'unknown argument: '
end
msg << unknown.join(' ')
msg << ' (note that options must come before arguments)' if unknown.detect { |v| v.start_with?('-') }
raise GLI::BadCommandLine, msg
end
end
|