raise exception on unknown option
This commit is contained in:
1 parent
b2b0d90c4d
commit
56e644e16e
3 files changed
+35
-5
No files matched your search
+24
-2
@@ -1,8 +1,30 @@
|
||||
require "yawpa/version"
|
||||
|
||||
# Example options configuration:
|
||||
# {
|
||||
# version: {},
|
||||
# verbose: {aliases: ['-v']},
|
||||
# get: {nargs: 1},
|
||||
# set: {nargs: 2},
|
||||
# }
|
||||
module Yawpa
|
||||
class UnknownOptionException < Exception; end
|
||||
|
||||
module_function
|
||||
def parse(config, params)
|
||||
return [[], params]
|
||||
def parse(params, options)
|
||||
opts = {}
|
||||
args = []
|
||||
i = 0
|
||||
while i < params.length
|
||||
param = params[i]
|
||||
if param[0] != '-'
|
||||
args << params[i]
|
||||
else
|
||||
opt_config = options[param] || options[param.to_sym]
|
||||
raise UnknownOptionException.new("Unknown option '#{param}'") if opt_config.nil?
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
return [opts, args]
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user