import opts
import location
+import version
class Message
super Comparable
# eg. `"Usage: tool [OPTION]... [FILE]...\nDo some things."`
var tooldescription: String writable = "Usage: [OPTION]... [ARG]..."
+ # Does `process_options` should accept an empty sequence of arguments.
+ # ie. nothing except options.
+ # Is `false` by default.
+ #
+ # If required, if should be set by the client before calling `process_options`
+ var accept_no_arguments writable = false
+
# print the full usage of the tool.
+ # Is called by `process_option` on `--help`.
# It also could be called by the client.
fun usage
do
end
# Parse and process the options given on the command line
- fun process_options
+ fun process_options(args: Sequence[String])
do
self.opt_warn.value = 1
# init options
option_context.parse(args)
+ if opt_help.value then
+ usage
+ exit 0
+ end
+
+ if opt_version.value then
+ print nit_version
+ exit 0
+ end
+
+ var errors = option_context.get_errors
+ if not errors.is_empty then
+ for e in errors do print "Error: {e}"
+ print tooldescription
+ print "Use --help for help"
+ exit 1
+ end
+
+ if option_context.rest.is_empty and not accept_no_arguments then
+ print tooldescription
+ print "Use --help for help"
+ exit 1
+ end
+
# Set verbose level
verbose_level = opt_verbose.value