Arguments parsing
From ESEwiki
Revision as of 13:41, 4 September 2006; view current revision
←Older revision | Newer revision→
←Older revision | Newer revision→
[edit]
Description
ARG makes argument parsing very simple, yet powerful. It allows one to describe how the command line should be dealt with, what do the arguments mean, and what are the available options.
Anonymous arguments, short options, and long options are supported. Short options may be aggregated. Options may be compulsory or optional, and may be set once or more.
[edit]
Usage
The simplest way to parse arguments is to inherit from ARG_CHECKER and fill in the blanks. Not too many blanks, though:
- The feature bad_arguments_code provides the integer value when something goes bad. That is the status code returned to the user when the program exits.
- The feature templates is a collection of command line templates. A template is a list or a set of options. Each list or set can contain lists and sets, and options. Options are strongly typed; currently ESE supports strings, integers and file names.
[edit]
Code example
class EXAMPLE
insert
ARG_CHECKER
create {ANY}
make
feature {}
make is
local
t: ARG_TEMPLATE
do
t := check_arguments
if t = Void then
std_error.put_string("Arguments expected!")
die_with_code(bad_arguments_code)
end
end
feature {} -- Arguments
Verbose_option: ARG_STANDALONE_OPTION is
once
create Result.make(False, False, "[
Set the verbose mode
]")
end
Help_option: ARG_STANDALONE_OPTION is
once
create Result.make(True, False, "[
Provide some help about the ESE bind builder
]")
end
Directory_option: ARG_FILE_OPTION is
once
create Result.make(False, False, "[
The <value> is a directory name
]")
end
Prefix_option: ARG_STRING_OPTION is
once
create Result.make(False, False, "[
The <value> is a random prefix
]")
end
Dtd_option: ARG_FILE_OPTION is
once
create Result.make(True, False, "[
The <value> is a name of the DTD to parse
]")
end
templates: COLLECTION[ARG_TEMPLATE] is
-- eseb -v --directory config -p ESEC_CONFIG esec.dtd
local
template_help, template_run: ARG_ARGUMENT_SET
do
create template_help.make
template_help.add_option(Help_option, {FAST_ARRAY[CHARACTER] << '?', 'h' >>}, "help")
create template_run.make
template_run.add_option(Verbose_option, {FAST_ARRAY[CHARACTER] << 'v' >>}, "verbose")
template_run.add_option(Directory_option, {FAST_ARRAY[CHARACTER] << 'd' >>}, "directory")
template_run.add_option(Prefix_option, {FAST_ARRAY[CHARACTER] << 'p' >>}, "prefix")
template_run.add_option(Dtd_option, Void, Void)
Result := {FAST_ARRAY[ARG_TEMPLATE] << template_help, template_run >>}
end
bad_arguments_code: INTEGER is -1
end

