X-Git-Url: http://nitlanguage.org diff --git a/lib/opts.nit b/lib/opts.nit index da78780..a7789f8 100644 --- a/lib/opts.nit +++ b/lib/opts.nit @@ -127,7 +127,7 @@ end # A count option. Count the number of time this option is present class OptionCount super Option - redef type VALUE: Int + redef type VALUE: Int is fixed # Init a new OptionCount with a `help` message and `names`. init(help: String, names: String...) is old_style_init do super(help, 0, names) @@ -236,7 +236,13 @@ class OptionInt super(help, default, names) end - redef fun convert(str) do return str.to_i + redef fun convert(str) + do + if str.is_int then return str.to_i + + errors.add "Expected an integer for option {names.join(", ")}." + return 0 + end end # An option with a Float as parameter @@ -286,9 +292,7 @@ class OptionContext private var optmap = new HashMap[String, Option] # Add one or more options to the context - fun add_option(opts: Option...) do - options.add_all(opts) - end + fun add_option(opts: Option...) do options.add_all(opts) # Display all the options available fun usage