Skip to content
Renaud Guillard edited this page Dec 8, 2020 · 11 revisions

The program interface definition schema details

This page gives a detailed view of the program interface definition schema nodes. For a complete view, read the full schema <<file ns/xsd/program/2.0/program.xsd>> To validate a XML file against the XSD schema, you can use xmllint (part of the Gnome XML toolkit)

#!bash
xmllint --noout --xinclude --schema ${NS_XML}/ns/xsd/program/2.0/program.xsd ${path-to-your-xml}

Namespace

The schema location of the &lt;program /&gt; schema is ##http://xsd.nore.fr/program##. The namespace ##prg## is generally used in XML documents.

#!xml
&lt;prg:program xmlns:prg="http://xsd.nore.fr/program" version="2.0" /&gt;

Shared nodes

Some nodes of the XML schema are used in various nodes.

documentation

A &lt;documentation /&gt; node can be added to most of element description nodes (&lt;program /&gt;, &lt;subcommand /&gt;, &lt;switch /&gt;, &lt;value /&gt;, ...). It may contains

  • &lt;abstract /&gt; whose content is a short inline description of the element

  • &lt;details /&gt; whose content is a more precise description. The content is a mix between text and some simple text formatting nodes

    • &lt;br /&gt; or &lt;endl /&gt; for line breaks
    • &lt;block&gt;details sub content&lt;/block&gt;

    #!xml <documentation> <abstract>A short description</abstract> <details>A less short description<endl />with more lines <block>An some nested block of text</block> </details> </documentation>

databinding

Options (switch, argument, multiargument and group) and values (value and other) may defines a variable name representing the option's value when generating parser code through XSLT stylesheets. The final name of the variable depends on the generated language.

#!xml
&lt;databinding&gt;
	&lt;variable&gt;var_name&lt;/variable&gt;
&lt;/databinding&gt;

names

All option nodes (except the special &lt;group /&gt; node) have at least one name. Option names are command line arguments starting with a single dash (ex. -h) for single-letter names and a double dash (ex. --help) for long names. Theses names are described in a names node and its sub nodes short and long.

#!xml
&lt;names&gt;
	&lt;short&gt;h&lt;/short&gt;
	&lt;long&gt;help&lt;/long&gt;
	&lt;long&gt;mayday&lt;/long&gt;
&lt;/names&gt;

The names node can contain any number of different short and long names. See also the Option name aliasing section of the specifications page.

ui

&lt;ui /&gt; nodes add special behaviors and informations for graphical frontend. The content of the &lt;ui /&gt; node depends of the parent node.

program

The &lt;program /&gt; node is the root of a full progrma XML document. It gives general informations about the program and its authors. The &lt;program /&gt; node may also contains:

  • a &lt;subcommands /&gt; node, to describes the program subcommands and their options.

  • a &lt;options /&gt; node, to describes the program global options.

  • a &lt;values /&gt; node, to desccribes positional arguments meanings.

    #!xml <program> <name>my_program</program> <author>Thor</author> <copyright>Copyright © 1337 by Leet (anonymous@hack.me)</copyright> <license>Distributed under the terms of the DO-WHAT-YOU-WANT license</license> <documentation> <!-- ... --> </documentation> <ui> <!-- A more user friendly name to display in a GUI --> <label>My Program</label> </ui> <subcommands> <!-- ... --> </subcommands> <options> <!-- ... --> </options> <values> <!-- ... --> </values> </program>

subcommands

A program may have a set of subcommands. The subcommand layout is commonly used in VCS system such as Mercurial

#!bash
hg add -S file1 file2 

The &lt;subcommands /&gt; node accepts a list of &lt;subcommand /&gt; node

#!xml
&lt;subcommands&gt;
	&lt;subcommand /&gt;
	&lt;subcommand /&gt;
	&lt;!-- ... --&gt;
&lt;subcommands/&gt;

subcommand

The &lt;subcommand /&gt; node describes a program subcommand. It must contains at least a &lt;name /&gt; node whose value is the main name of the subcommand. It also accept

  • one or more &lt;alias /&gt; names in a &lt;aliases /&gt; node

  • one &lt;options /&gt; node

  • one &lt;values /&gt; node

    #!xml <subcommand> <name>commit</name> <aliases> <alias>ci</alias> <alias>store</alias> </aliases> <options> <!-- ... --> </options> <values> <!-- ... --> </values> <subcommand/>

options

Contains a set of option nodes

#!xml
&lt;options&gt;
	&lt;switch&gt;
		&lt;!-- ... --&gt;
	&lt;/switch&gt;
	&lt;argument&gt;
		&lt;!-- ... --&gt;
	&lt;/argument&gt;
&lt;/options&gt;

The &lt;options /&gt; node can be used as a root node of an XML document to create a library of common options.

switch

Describes an option without argument.

#!xml
&lt;switch id="optional_id"&gt;
	&lt;databinding&gt;
		&lt;variable&gt;hasSwitch&lt;/variable&gt;
	&lt;/databinding&gt;
	&lt;documentation&gt;
		&lt;abstract&gt;Simple switch&lt;/abstract&gt;
		&lt;details&gt;A simple switch option (true/false)&lt;/details&gt;
	&lt;/documentation&gt;
	&lt;names&gt;
		&lt;short&gt;s&lt;/short&gt;
		&lt;long&gt;simpleswitch&lt;/long&gt;
	&lt;/names&gt;
	&lt;ui mode="default"&gt;
		&lt;label&gt;GUI Switch label&lt;/label&gt; 
	&lt;/ui&gt;
&lt;/switch&gt;

If the option is present on the command line, the value of the bound variable will be true. Otherwise, false. The &lt;ui /&gt; node may specify the way the switch is displayed by specifying the mode attribute

  • default (the default): The option will be visible as a checkbox or a radiobutton.
  • hidden: The switch will allways be set to true and will be hidden in the GUI.
  • disabled: The option will not be available in the GUI and will not be set.

argument

Describes an option with a single parameter.

#!xml
&lt;argument&gt;
	&lt;databinding&gt;
		&lt;variable&gt;dgarg&lt;/variable&gt;
	&lt;/databinding&gt;
	&lt;documentation&gt;
		&lt;abstract&gt;Single argument option&lt;/abstract&gt;
	&lt;/documentation&gt;
	&lt;names&gt;
		&lt;long&gt;argument-option&lt;/long&gt;
		&lt;short&gt;a&lt;/short&gt;
	&lt;/names&gt;
	&lt;default&gt;Default value&lt;/default&gt;
	&lt;ui mode="hidden"&gt;
		&lt;label&gt;GUI friendly label&lt;/label&gt;
		&lt;value&gt;Value for GUI frontend&lt;/value&gt;
	&lt;/ui&gt;
&lt;/argument&gt;

The value of the bound variable will be

  • the string given by the following positional argument, if the option is present on the command line,
  • the content of the &lt;default /&gt; node
  • An empty string otherwise

The &lt;ui /&gt; node may specify a specific value to use when the option mode is "hidden".

Option value restrictions

A (non-)restrictive list of value can be set with the &lt;select /&gt; node.

#!xml
&lt;select restrict="true"&gt;
	&lt;option&gt;Value A&lt;/option&gt;
	&lt;option&gt;2nd value&lt;/option&gt;
	&lt;option&gt;Yet another possible value&lt;/option&gt;
&lt;/select&gt;

&lt;select /&gt; is used in various way:

  • by the bash completion generator to suggest more accurate items to the user
  • by the parser generators to automatically check arguments values and raise errors if needed

The @restrict attribute can be set to true to limit possible values to those described in the &lt;option /&gt; nodes. Otherwise, the &lt;select /&gt; node will only be used as a hint.

Option value types

The type of argument expected by the option may also be described using the &lt;type /&gt; subnode

#!xml
&lt;argument&gt;
	&lt;!-- ... --&gt;
	&lt;type&gt;
		&lt;number min="1.0" max="10.0" decimal="2" /&gt;
	&lt;/type&gt;
&lt;/argument&gt;
  • by the bash completion generator to suggest more accurate items to the user
  • by the parser generators to automatically check arguments values and raise errors if needed
  • &lt;existingcommand /&gt; An executable available in the user path
  • &lt;hostname /&gt; A host name
  • &lt;mixed /&gt; May contain anything (alias of &lt;string /&gt;)
  • &lt;number /&gt; A numeric value
  • &lt;path /&gt; A file system path
  • &lt;string /&gt; May contain anything
number

&lt;number /&gt; may specify

  • @min to set a minimal accepted value (v &gt;= @min)
  • @min to set a maximal accepted value (v &lt;= @max)
  • @decimal to set the number of decimal to use for a floating point number
path

The &lt;path /&gt; node has two optional attributes.

#!xml
&lt;path access="rw" exists="true" /&gt;

The @access attribute will filter file path by permissions. @access value have to be a combination of the characters 'r', 'w' and 'x'

  • 'r': Readable file
  • 'w': Writable file
  • 'x': Executable file

The @exist attribute specify that the path must exists. The only accepted value for this attribute is true. The kind of file system item expected is defined with the sub node &lt;kinds /&gt;

#!xml
&lt;path&gt;
	&lt;kinds&gt;
		&lt;folder /&gt;
		&lt;file /&gt;
		&lt;socket /&gt;
		&lt;symlink /&gt;
	&lt;/kinds&gt;
&lt;/path&gt;

A set of name patterns rules can be set using the &lt;patterns /&gt; subnode

#!xml
&lt;path&gt;
	&lt;patterns&gt;
		&lt;pattern&gt;
			&lt;name&gt;XML-based files&lt;/name&gt;
			&lt;rules&gt;
				&lt;rule&gt;
					&lt;endWith&gt;.xml&lt;/endWith&gt;
				&lt;/rule&gt;
				&lt;rule&gt;
					&lt;endWith&gt;.xsl&lt;/endWith&gt;
				&lt;/rule&gt;
			&lt;/rules&gt;
		&lt;/pattern&gt;
		&lt;pattern&gt;
			&lt;name&gt;Linux System configuration path&lt;/name&gt;
			&lt;rules&gt;
				&lt;rule&gt;
					&lt;startWith&gt;/etc&lt;/startWith&gt;
				&lt;/rule&gt;
			&lt;/rules&gt;
		&lt;/pattern&gt;
	&lt;/patterns&gt;
&lt;/path&gt;

multiargument

Describes an option which will accept one or more parameters. The &lt;multiargument/&gt; node has the same sub nodes as the &lt;argument /&gt; minus the &lt;default /&gt; one and add optional @min and @max attributes to set the minimum and maximum number of parameters accepted.

group

Describes a sub group of options.

#!xml
&lt;group type="exclusive"&gt;
	&lt;options&gt;
		&lt;!-- ... Sub options --&gt;
		&lt;switch&gt;
			&lt;names&gt;&lt;short&gt;a&lt;/short&gt;&lt;/names&gt;
		&lt;/switch&gt;
		&lt;switch&gt;
			&lt;names&gt;&lt;short&gt;b&lt;/short&gt;&lt;/names&gt;
		&lt;/switch&gt;
	&lt;/options&gt;
&lt;/group&gt;

The optional @type attribute with a value set to exclusive specify that only one option of the group can be present on the same command line. In the example above, writing program -a -b will not be allowed.
If @type is not present, the &lt;group /&gt; will not have any particular incidence on the command line parsing.

  • &lt;documentation /&gt;
  • &lt;databinding /&gt;
  • &lt;options /&gt;

values

Describes particular meanings of positional arguments (non-option).

mv -f from to

In the mv command, from and to are not options nor options arguments. from is the first positional argument and to the second.

  • zero or more &lt;value /&gt; node

  • then, zero or one &lt;other /&gt; node

    #!xml <program> <values> <value> <!-- First positional argument description --> </value> <value> <!-- Second positional argument description --> </value> <other> <!-- Other positional arguments description --> </other> </values> <subcommands> <subcommand> <name>...</name> <values> <!-- positional arguments meaning in the subcommand context --> <value /> <other /> </values> </subcommand> </subcommands> </program>

Values can't be bound to a specific variable using &lt;databinding/&gt; node. They are generally represented as an indexed array variable (ex: parser_values[*] in the shell, or result.values in Python) If no &lt;values/&gt; node is present in a program or a subcommand description, this program (or subcommand) will treat any non-recognized command line argument as an error. If no &lt;other /&gt; node is set, the n+1th value and the following will be treated as errors (where n is the number of &lt;value /&gt; nodes)

value

Describes one positional argument meaning. The &lt;value /&gt; accepts the same nodes as the &lt;argument /&gt; node except &lt;databinding /&gt; and &lt;default /&gt;

other

Describes all other possible positional arguments after zero or more specifically defined ones using &lt;value/&gt;. The &lt;other/&gt; node accepts the same nodes as the &lt;multiargument /&gt; node except &lt;databinding /&gt;

The program interface definition framework

Clone this wiki locally