1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 var ctx
= new OptionContext
18 var ot
= new OptionText("List of options")
19 var ob
= new OptionBool("Test of OptionBool", "-b", "--bool")
20 var oc
= new OptionCount("Test of OptionCount", "-c", "--count")
21 var os
= new OptionString("Test of OptionString", "-s", "--string")
22 var oi
= new OptionInt("Test of OptionInt", 10, "-i", "--int")
23 var oa
= new OptionArray("Test of OptionArray", "-a", "--array")
24 var oe
= new OptionEnum(["zero", "one", "two", "tree"], "Test of OptionEnum", 1, "-e", "--enum")
25 ctx
.add_option
(ot
, ob
, oc
, os
, oi
, oa
, oe
)
29 print
"Arguments: {args.length}"
34 print
"Rest: {ctx.rest.length}"
39 var errors
= ctx
.errors
40 if errors
.not_empty
then
41 print
"Errors: {errors.length}"
42 print ctx
.errors
.join
("\n")
45 print
"OptionBool: {ob.value}"
46 print
"OptionCount: {oc.value}"
47 if os
.value
== null then os
.value
= ""
48 print
"OptionString: {os.value.to_s}"
49 print
"OptionInt: {oi.value}"
50 print
"OptionArray: {oa.value}"
51 print
"OptionEnum: {oe.value}"