lib/opt: add OptionCount
authorJean Privat <jean@pryen.org>
Tue, 23 Jun 2009 19:11:50 +0000 (15:11 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:48:19 +0000 (15:48 -0400)
An option count works like a OptionBool except it counts the number of
occurrences of the flag.

Signed-off-by: Jean Privat <jean@pryen.org>

lib/opts.nit

index 81b9a98..b4da3f5 100644 (file)
@@ -97,6 +97,15 @@ special Option
        redef meth read_param(it) do value = true
 end
 
+class OptionCount
+special Option
+       redef type VALUE: Int
+
+       init(help: String, names: String...) do init_opt(help, 0, names)
+
+       redef meth read_param(it) do value += 1
+end
+
 # Option with one mandatory parameter
 class OptionParameter
 special Option