contrib/objcwrapper: intro basic framework for command line options
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 20 Aug 2015 20:58:20 +0000 (16:58 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 21 Aug 2015 19:05:27 +0000 (15:05 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/objcwrapper/src/objcwrapper.nit

index 3a941ed..d697cf5 100644 (file)
 # Generator of Nit modules to wrap Objective-C services
 module objcwrapper
 
+import nitcc_runtime
+import opts
+
 import objc_visitor
 import objc_model
 import objc_generator
-
-import nitcc_runtime
 import objc_lexer
 import objc_parser
 
+var opt_help = new OptionBool("Show this help message", "-h", "--help")
+
+var opts = new OptionContext
+opts.add_option(opt_help, opt_output)
+opts.parse(args)
+
+if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then
+       print """
+Usage: objcwrapper [options] input_file [other_input_file [...]]
+Options:"""
+       opts.usage
+
+       if opt_help.value then exit 0
+       exit 1
+end
+
 var v = new Interpretor
 var g = new CodeGenerator
 
-for arg in args do
+for arg in opts.rest do
        # Read input
        var content = arg.to_path.read_all