nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update NOTICE and LICENSE
[nit.git]
/
lib
/
opts.nit
diff --git
a/lib/opts.nit
b/lib/opts.nit
index
1673215
..
1d085b8
100644
(file)
--- a/
lib/opts.nit
+++ b/
lib/opts.nit
@@
-11,6
+11,9
@@
# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
+# Manage options on the command line
+module opts
+
# Super class of all option's class
class Option
# Names for the option (including long and short ones)
# Super class of all option's class
class Option
# Names for the option (including long and short ones)
@@
-69,9
+72,8
@@
class Option
fun pretty_default: String
do
fun pretty_default: String
do
- if default_value != null then
- return " ({default_value})"
- end
+ var dv = default_value
+ if dv != null then return " ({dv})"
return ""
end
return ""
end
@@
-80,7
+82,7
@@
class Option
end
class OptionText
end
class OptionText
-special Option
+ super Option
init(text: String) do init_opt(text, null, null)
redef fun pretty(off) do return to_s
init(text: String) do init_opt(text, null, null)
redef fun pretty(off) do return to_s
@@
-89,7
+91,7
@@
special Option
end
class OptionBool
end
class OptionBool
-special Option
+ super Option
redef type VALUE: Bool
init(help: String, names: String...) do init_opt(help, false, names)
redef type VALUE: Bool
init(help: String, names: String...) do init_opt(help, false, names)
@@
-98,7
+100,7
@@
special Option
end
class OptionCount
end
class OptionCount
-special Option
+ super Option
redef type VALUE: Int
init(help: String, names: String...) do init_opt(help, 0, names)
redef type VALUE: Int
init(help: String, names: String...) do init_opt(help, 0, names)
@@
-108,7
+110,7
@@
end
# Option with one mandatory parameter
class OptionParameter
# Option with one mandatory parameter
class OptionParameter
-special Option
+ super Option
protected fun convert(str: String): VALUE is abstract
redef fun read_param(it)
protected fun convert(str: String): VALUE is abstract
redef fun read_param(it)
@@
-125,7
+127,7
@@
special Option
end
class OptionString
end
class OptionString
-special OptionParameter
+ super OptionParameter
redef type VALUE: nullable String
init(help: String, names: String...) do init_opt(help, null, names)
redef type VALUE: nullable String
init(help: String, names: String...) do init_opt(help, null, names)
@@
-134,27
+136,29
@@
special OptionParameter
end
class OptionEnum
end
class OptionEnum
-special OptionParameter
+ super OptionParameter
redef type VALUE: Int
redef type VALUE: Int
- var _enum: Array[String]
+ var _values: Array[String]
- init(enum: Array[String], help: String, default: Int, names: String...)
+ init(values: Array[String], help: String, default: Int, names: String...)
do
do
- assert enum.length > 0
- _enum = enum.to_a
- init_opt("{help} <{enum.join(", ")}>", default, names)
+ assert values.length > 0
+ _values = values.to_a
+ init_opt("{help} <{values.join(", ")}>", default, names)
end
redef fun convert(str)
do
end
redef fun convert(str)
do
- var id = _enum.index_of(str)
+ var id = _values.index_of(str)
return id
end
return id
end
+ fun value_name: String = _values[value]
+
redef fun pretty_default
do
if default_value != null then
redef fun pretty_default
do
if default_value != null then
- return " ({_enum[default_value.as(not null)]})"
+ return " ({_values[default_value.as(not null)]})"
else
return ""
end
else
return ""
end
@@
-162,7
+166,7
@@
special OptionParameter
end
class OptionInt
end
class OptionInt
-special OptionParameter
+ super OptionParameter
redef type VALUE: Int
init(help: String, default: Int, names: String...) do init_opt(help, default, names)
redef type VALUE: Int
init(help: String, default: Int, names: String...) do init_opt(help, default, names)
@@
-171,7
+175,7
@@
special OptionParameter
end
class OptionArray
end
class OptionArray
-special OptionParameter
+ super OptionParameter
redef type VALUE: Array[String]
init(help: String, names: String...)
redef type VALUE: Array[String]
init(help: String, names: String...)