Readarghh simplifies the usage of the sofa library class SOFA_ARGUMENT_PARSER. It creates a wrapper class for a given dos.library/ReadArgs() template that allows to access argument values via Eiffel attributes instead of cryptic indeces. Additionally, it declares the attributes of the proper type (BOOLEAN, INTEGER, STRING, ARRAY[STRING]) depending on the modifier in the template.
readarghh to/k/a,template/a,description,quiet/s
The command line arguments have the following meaning:
Invoking readarghh like
readarghh to=eiffel/copy_arguments.e file/m/a,to/a,quiet/s "Arguments for copy"
gives a class source with the following short form:
class interface COPY_ARGUMENTS
creation
make
feature(s) from COPY_ARGUMENTS
-- Initialization
make
feature(s) from COPY_ARGUMENTS
-- Access
file: ARRAY[STRING]
-- value of argument "file"
to: STRING
-- value of argument "to"
quiet: BOOLEAN
-- value of argument "quiet"
feature(s) from COPY_ARGUMENTS
-- Status change
parse
-- Parse arguments from CLI and set corresponding attributes.
require
not_yet_parsed: not is_parsed
reset
-- Prepare for another `parse'.
ensure
not_parsed: not is_parsed
feature(s) from COPY_ARGUMENTS
-- Status report
is_parsed: BOOLEAN
-- Has `parse' been called already ?
has_error: BOOLEAN
-- Did `parse' cause an error ?
error_description: STRING
-- description of last error to be shown to end user
invariant
consistent_parsed: is_parsed implies not has_error;
consistent_error: has_error implies error_description /= Void;
end of COPY_ARGUMENTS
The attributes file, to and quiet give access to the command line arguments. To set the values, use parse like this:
options: COPY_ARGUMENTS ... !!options.make options.parse
After parsing, check for errors and either go on and use the argument values, or display an error message:
if not options.has_error then
...
-- Use `options.file', `options.to' and
-- `options.quit' for whatever purpose.
...
else
print(options.error_description)
print('%N')
end;