Global Variables and Constants categories
I/O, Modules and System Interface
Command line handling
Serialization

Command line handling [XL]

In XL CLAIRE, additionally to the main @ list redefinition, we have a command line processor that make a module able to define a particular set of option responder and associated command line documentation through 2 handlers. For instance the Reader implement the option -f used to load a file from the command line. The Reader implements :
 [option_usage(opt:{"-f""-ef"}) : tuple(stringstringstring->
     tuple("Load file",
             "{-f | -ef} <file:path> ...",
             "Load the CLAIRE file(s) <file>. The given path may contain an extension " /+
             "assuming .cl by default. When the <-f> option is used, the file is " /+
             "assumed to contain CLAIRE definitions (variables, class, methods) whereas " /+
             " <-ef> attempts to read a file made of CLAIRE expression.")]


 [option_respond(opt:{"-f""-ef"}, l:list: void ->
     if not(linvalid_option_argument(),
     if (not(isfile?(l[1])) & not(isfile?(l[1] /+ ".cl")))
         error("~A cannot be opened"l[1]),
     while (l & (isfile?(l[1]) | isfile?(l[1] /+ ".cl")))
         let path := l[1]
         in (l << 1,
             case opt
                 ({"-f"load(path),
                 {"-ef"eload(path)))]
It comes with this implementation that when an executable is linked with a set of module the whole option set defined by these module is implicitly supported by the executable. For instance, when an executable is linked with the Reader module is support the -f option.

Additionally to this two handlers, a module can define a single restriction of option_parsed that will be called once the full command line has been parsed. With such an handler, a module can perform a job that depends on multiple independent option responder (that would have initialize global flags). For instance :
 *myopt*:boolean := false

 [option_respond(opt:{"myopt"}, l:list: void -> *myopt* := true]

 [option_parsed() : void ->
     if *myopt* ...
     else ...]
Restrictions of option_usage are used by the command line help which is handled with the particular option -h in the Core module :
 {-h | -help+[<m| <option| <index>]
Which would provide the help for all options defined by a module <m> or for a particular option <option> or for the option having the index <index> in the option index as generated by option -h when used without arguments.


categories Command line handlingnormal dispatch [XL] Core interface

option_parsed :: property(open = 3)

A module can define a single option_parsed restriction that will be called by the command line option parser at startup as soon as the full command line is parsed. It will be used inside a module to perform an operation that rely on multiple options (for which option_respond as already been called):
 option_parsed() : void ->
     ...


categories Command line handlingnormal dispatch [XL] Core interface

option_respond :: property(open = 3)

A module can define multiple option_respond restrictions that will be called by the command line option parser at startup. option_respond will take two arguments:
 option_respond(opt:{"-opt"}, l:list[string]) : void ->
     ...

It is up to the handler to remove used arguments from the given list.


categories Command line handlingnormal dispatch [XL] Core interface

option_usage :: property(open = 3)

A module can define multiple option_usage restrictions that will be called by the command line option parser when the command line help is invoked. option_usage takes a single argument that is a constant set that contain names of multiple related options. The handler should return of tuple of 3 strings :

 option_usage(opt:{"-opt"}) : tuple(stringstringstring->
     tuple("short description",
             "-opt <f:file>",
             "long description on how to use option -opt
             we may use <f> to reference the argument f
             it can also span multiple line if needed"
)
The usage should be written following a few guidelines such the command line help can produce a description with a nice appearance :