nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
modelize_property: use resolve_mtype_unchecked during build_signature
[nit.git]
/
lib
/
opts.nit
diff --git
a/lib/opts.nit
b/lib/opts.nit
index
8f2dc48
..
fa5ce15
100644
(file)
--- a/
lib/opts.nit
+++ b/
lib/opts.nit
@@
-48,6
+48,9
@@
abstract class Option
init_opt(help, default, names)
end
init_opt(help, default, names)
end
+ # Init option `helptext`, `default_value` and `names`.
+ #
+ # Also set current `value` to `default`.
fun init_opt(help: String, default: VALUE, names: nullable Array[String])
do
if names == null then
fun init_opt(help: String, default: VALUE, names: nullable Array[String])
do
if names == null then
@@
-79,6
+82,7
@@
abstract class Option
return text.to_s
end
return text.to_s
end
+ # Pretty print the default value.
fun pretty_default: String
do
var dv = default_value
fun pretty_default: String
do
var dv = default_value
@@
-97,6
+101,7
@@
end
class OptionText
super Option
class OptionText
super Option
+ # Init a new OptionText with `text`.
init(text: String) is old_style_init do super(text, null, null)
redef fun pretty(off) do return to_s
init(text: String) is old_style_init do super(text, null, null)
redef fun pretty(off) do return to_s
@@
-109,6
+114,7
@@
class OptionBool
super Option
redef type VALUE: Bool
super Option
redef type VALUE: Bool
+ # Init a new OptionBool with a `help` message and `names`.
init(help: String, names: String...) is old_style_init do super(help, false, names)
redef fun read_param(it)
init(help: String, names: String...) is old_style_init do super(help, false, names)
redef fun read_param(it)
@@
-123,6
+129,7
@@
class OptionCount
super Option
redef type VALUE: Int
super Option
redef type VALUE: Int
+ # Init a new OptionCount with a `help` message and `names`.
init(help: String, names: String...) is old_style_init do super(help, 0, names)
redef fun read_param(it)
init(help: String, names: String...) is old_style_init do super(help, 0, names)
redef fun read_param(it)
@@
-135,6
+142,8
@@
end
# Option with one parameter (mandatory by default)
abstract class OptionParameter
super Option
# Option with one parameter (mandatory by default)
abstract class OptionParameter
super Option
+
+ # Convert `str` to a value of type `VALUE`.
protected fun convert(str: String): VALUE is abstract
# Is the parameter mandatory?
protected fun convert(str: String): VALUE is abstract
# Is the parameter mandatory?
@@
-159,6
+168,7
@@
class OptionString
super OptionParameter
redef type VALUE: nullable String
super OptionParameter
redef type VALUE: nullable String
+ # Init a new OptionString with a `help` message and `names`.
init(help: String, names: String...) is old_style_init do super(help, null, names)
redef fun convert(str) do return str
init(help: String, names: String...) is old_style_init do super(help, null, names)
redef fun convert(str) do return str
@@
-170,8
+180,13
@@
end
class OptionEnum
super OptionParameter
redef type VALUE: Int
class OptionEnum
super OptionParameter
redef type VALUE: Int
+
+ # Values in the enumeration.
var values: Array[String]
var values: Array[String]
+ # Init a new OptionEnum from `values` with a `help` message and `names`.
+ #
+ # `default` is the index of the default value in `values`.
init(values: Array[String], help: String, default: Int, names: String...) is old_style_init do
assert values.length > 0
self.values = values.to_a
init(values: Array[String], help: String, default: Int, names: String...) is old_style_init do
assert values.length > 0
self.values = values.to_a
@@
-189,6
+204,7
@@
class OptionEnum
return id
end
return id
end
+ # Get the value name from `values`.
fun value_name: String do return values[value]
redef fun pretty_default
fun value_name: String do return values[value]
redef fun pretty_default
@@
-202,6
+218,7
@@
class OptionInt
super OptionParameter
redef type VALUE: Int
super OptionParameter
redef type VALUE: Int
+ # Init a new OptionInt with a `help` message, a `default` value and `names`.
init(help: String, default: Int, names: String...) is old_style_init do
super(help, default, names)
end
init(help: String, default: Int, names: String...) is old_style_init do
super(help, default, names)
end
@@
-214,6
+231,7
@@
class OptionFloat
super OptionParameter
redef type VALUE: Float
super OptionParameter
redef type VALUE: Float
+ # Init a new OptionFloat with a `help` message, a `default` value and `names`.
init(help: String, default: Float, names: String...) is old_style_init do
super(help, default, names)
end
init(help: String, default: Float, names: String...) is old_style_init do
super(help, default, names)
end
@@
-227,6
+245,7
@@
class OptionArray
super OptionParameter
redef type VALUE: Array[String]
super OptionParameter
redef type VALUE: Array[String]
+ # Init a new OptionArray with a `help` message and `names`.
init(help: String, names: String...) is old_style_init do
values = new Array[String]
super(help, values, names)
init(help: String, names: String...) is old_style_init do
values = new Array[String]
super(help, values, names)
@@
-354,6
+373,7
@@
class OptionContext
end
end
end
end
+ # Options parsing errors.
fun get_errors: Array[String]
do
var errors = new Array[String]
fun get_errors: Array[String]
do
var errors = new Array[String]