From 0e56fe29a9afeee00e02e722496678df89d37d50 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 17 Nov 2009 13:59:39 +0200 Subject: Complete the implementation of the option documentation Add the man page generator. Port CLI usage, HTML documentation and the man page to the auto-generated version. Update examples and documentation. --- doc/cli-epilogue.1 | 21 ++++ doc/cli-epilogue.xhtml | 24 +++++ doc/cli-prologue.1 | 59 ++++++++++ doc/cli-prologue.xhtml | 79 ++++++++++++++ doc/cli.1 | 223 ++++++++++++++++++++++---------------- doc/cli.xhtml | 199 ++++++++++++++++++++++------------ doc/guide/index.xhtml | 284 ++++++++++++++++++++++++++++++++++++++++++++----- doc/makefile | 26 ++++- 8 files changed, 727 insertions(+), 188 deletions(-) create mode 100644 doc/cli-epilogue.1 create mode 100644 doc/cli-epilogue.xhtml create mode 100644 doc/cli-prologue.1 create mode 100644 doc/cli-prologue.xhtml (limited to 'doc') diff --git a/doc/cli-epilogue.1 b/doc/cli-epilogue.1 new file mode 100644 index 0000000..cd2348d --- /dev/null +++ b/doc/cli-epilogue.1 @@ -0,0 +1,21 @@ +.\" +.\" DIAGNOSTICS +.\" +.SH DIAGNOSTICS +If the input file is not a valid CLI definition, +.B cli +will issue diagnostic messages to STDERR and exit with non-zero exit code. +.\" +.\" BUGS +.\" +.SH BUGS +Send bug reports to the cli-users@codesynthesis.com mailing list. +.\" +.\" COPYRIGHT +.\" +.SH COPYRIGHT +Copyright (c) 2009 Code Synthesis Tools CC. + +Permission is granted to copy, distribute and/or modify this document under +the terms of the MIT License. Copy of this license can be obtained from +http://www.codesynthesis.com/licenses/mit.txt diff --git a/doc/cli-epilogue.xhtml b/doc/cli-epilogue.xhtml new file mode 100644 index 0000000..ea0a34a --- /dev/null +++ b/doc/cli-epilogue.xhtml @@ -0,0 +1,24 @@ +

DIAGNOSTICS

+ +

If the input file is not a valid CLI definition, cli + will issue diagnostic messages to STDERR and exit with non-zero exit + code.

+ +

BUGS

+ +

Send bug reports to the + cli-users@codesynthesis.com mailing list.

+ + + + + + diff --git a/doc/cli-prologue.1 b/doc/cli-prologue.1 new file mode 100644 index 0000000..5d3953b --- /dev/null +++ b/doc/cli-prologue.1 @@ -0,0 +1,59 @@ +.\" Process this file with +.\" groff -man -Tascii cli.1 +.\" +.TH CLI 1 "October 2009" "CLI 1.0.0" +.SH NAME +cli \- command line interface compiler for C++ +.\" +.\" +.\" +.\"-------------------------------------------------------------------- +.SH SYNOPSIS +.\"-------------------------------------------------------------------- +.B cli +.B [ +.I options +.B ] +.I file +.\" +.\" +.\" +.\"-------------------------------------------------------------------- +.SH DESCRIPTION +.\"-------------------------------------------------------------------- +.B cli +generates C++ implementation and documentation in various formats for a +command line interface defined in the CLI language. For an input file in +the form +.B name.cli +the following is generated. By default or if the +.B --generate-cxx +option is specified, the following C++ files are generated: +.B name.hxx +(header file), +.B name.ixx +(inline file, generated unless the +.B --suppress-inline +option is specified), and +.B name.cxx (source file). +If the +.B --generate-html +option is specified, then the +.B name.html +HTML documentation file is generated. If the +.B --generate-man +option is specified, then the +.B name.1 +man page file is generated. When +.B --generate-html +or +.B --generate-man +is specified, the +.B --stdout +option can be used to redirect the output to STDOUT instead of a file. +.\" +.\" +.\" +.\"-------------------------------------------------------------------- +.SH OPTIONS +.\"-------------------------------------------------------------------- diff --git a/doc/cli-prologue.xhtml b/doc/cli-prologue.xhtml new file mode 100644 index 0000000..71108e1 --- /dev/null +++ b/doc/cli-prologue.xhtml @@ -0,0 +1,79 @@ + + + + + CLI 1.0.0 Compiler Command Line Manual + + + + + + + + + + + +
+
+ +

NAME

+ +

cli - command line interface compiler for C++

+ +

SYNOPSIS

+ +
+
cli [options] file
+
+ +

DESCRIPTION

+ +

cli generates C++ implementation and + documentation in various formats for a command line interface + defined in the CLI language. For an input file in the form + name.cli the following is generated. By + default or if the --generate-cxx option is + specified, the following C++ files are generated: + name.hxx (header file), name.ixx + (inline file, generated unless the --suppress-inline + option is specified), and name.cxx (source file). + If the --generate-html option is specified, then + the name.html HTML documentation file is generated. + If the --generate-man option is specified, then + the name.1 man page file is generated. When + --generate-html or --generate-man + is specified, the --stdout option can be used to + redirect the output to STDOUT instead of a file.

+ +

OPTIONS

diff --git a/doc/cli.1 b/doc/cli.1 index 80e3bc6..2e9f180 100644 --- a/doc/cli.1 +++ b/doc/cli.1 @@ -22,10 +22,13 @@ cli \- command line interface compiler for C++ .SH DESCRIPTION .\"-------------------------------------------------------------------- .B cli -generates a C++ implementation for a command line interface defined in the CLI -language. For an input file in the form +generates C++ implementation and documentation in various formats for a +command line interface defined in the CLI language. For an input file in +the form .B name.cli -the following C++ files are generated: +the following is generated. By default or if the +.B --generate-cxx +option is specified, the following C++ files are generated: .B name.hxx (header file), .B name.ixx @@ -33,95 +36,139 @@ the following C++ files are generated: .B --suppress-inline option is specified), and .B name.cxx (source file). +If the +.B --generate-html +option is specified, then the +.B name.html +HTML documentation file is generated. If the +.B --generate-man +option is specified, then the +.B name.1 +man page file is generated. When +.B --generate-html +or +.B --generate-man +is specified, the +.B --stdout +option can be used to redirect the output to STDOUT instead of a file. .\" .\" .\" .\"-------------------------------------------------------------------- .SH OPTIONS .\"-------------------------------------------------------------------- -.IP "\fB\--help\fR" -Print usage information and exit. - -.IP "\fB\--version\fR" -Print version and exit. - -.IP "\fB\--output-dir\fR | \fB\-o \fIdir\fR" -Write generated files to -.I dir -instead of the current directory. - -.IP "\fB\--suppress-inline\fR" -Generate all functions non-inline. By default simple functions are made -inline. This option suppresses creation of the inline file. - -.IP "\fB\--hxx-suffix \fIsuffix\fR" -Use the provided -.I suffix -instead of the default -.B .hxx -to construct the name of the generated header file. - -.IP "\fB\--ixx-suffix \fIsuffix\fR" -Use the provided -.I suffix -instead of the default -.B .ixx -to construct the name of the generated inline file. - -.IP "\fB\--cxx-suffix \fIsuffix\fR" -Use the provided -.I suffix -instead of the default -.B .cxx -to construct the name of the generated source file. - -.IP "\fB\--option-prefix \fIprefix\fR" -Use the provided -.I prefix -instead of the default -.B - -as an option prefix. Unknown command line arguments that start with this -prefix are treated as unknown options. If you set the option prefix to the -empty value, then all the unknown command line arguments will be treated as -program arguments. - -.IP "\fB\--option-separator \fIseparator\fR" -Use the provided -.I separator -instead of the default -.B -- -as an optional separator between options and arguments. All the command line -arguments that are parsed after this separator are treated as program -arguments. Set the option separator to the empty value if you don't want -this functionality. - -.IP "\fB\--include-with-brackets\fR" -Use angle brackets (<>) instead of quotes ("") in generated -.B #include -directives. - -.IP "\fB\--include-prefix \fIprefix\fR" -Add -.I prefix -to generated -.B #include -directive paths. - -.IP "\fB\--guard-prefix \fIprefix\fR" -Add -.I prefix -to generated header inclusion guards. The prefix is transformed to upper -case and characters that are illegal in a preprocessor macro name are -replaced with underscores. - -.IP "\fB\--reserved-name \fIname\fR[\fB=\fIrep\fR]" -Add -.I name -to the list of names that should not be used as identifiers. The name -can optionally be followed by -.B = -and the replacement name that should be used instead. All C++ keywords -are already in this list. +.\" +.\" The following documentation was generated by CLI, a command +.\" line interface compiler for C++. +.\" +.IP "\fB--help\fP" +Print usage information and exit\. + +.IP "\fB--version\fP" +Print version and exit\. + +.IP "\fB--output-dir\fP|\fB-o\fP \fIdir\fP" +Write the generated files to \fIdir\fP instead of the current directory\. + +.IP "\fB--suppress-inline\fP" +Generate all functions non-inline\. By default simple functions are made +inline\. This option suppresses creation of the inline file\. + +.IP "\fB--suppress-usage\fP" +Suppress the generation of the usage printing code\. + +.IP "\fB--long-usage\fP" +If no short documentation string is provided, use the complete long +documentation string in usage\. By default, in this situation only the first +sentence from the long string is used\. + +.IP "\fB--option-length\fP \fIlen\fP" +Indent option descriptions \fIlen\fP characters when printing usage\. This +is useful when you have multiple options classes, potentially in separate +files, and would like their usage to have the same indentation level\. + +.IP "\fB--generate-cxx\fP" +Generate C++ code\. If neither \fB--generate-man\fP nor +\fB--generate-html\fP is specified, this mode is assumed by default\. + +.IP "\fB--generate-man\fP" +Generate documentation in the man page format\. + +.IP "\fB--generate-html\fP" +Generate documentation in the HTML format\. + +.IP "\fB--man-prologue\fP \fIfile\fP" +Insert the content of \fIfile\fP at the beginning of the man page file\. + +.IP "\fB--man-epilogue\fP \fIfile\fP" +Insert the content of \fIfile\fP at the end of the man page file\. + +.IP "\fB--html-prologue\fP \fIfile\fP" +Insert the content of \fIfile\fP at the beginning of the HTML file\. + +.IP "\fB--html-epilogue\fP \fIfile\fP" +Insert the content of \fIfile\fP at the end of the HTML file\. + +.IP "\fB--class\fP \fIfq-name\fP" +Generate the man page or HTML documentation only for the \fIfq-name\fP +options class\. The \fIfq-name\fP name should be a fully-qualified options +class name, for example, \fBapp::options\fP\. This functionality is useful +if you need to insert custom documentation between options belonging to +different classes\. + +.IP "\fB--stdout\fP" +Write output to STDOUT instead of a file\. This option is not valid when +generating C++ code and is normally used to combine generated documentation +for several option classes in a single file\. + +.IP "\fB--hxx-suffix\fP \fIsuffix\fP" +Use \fIsuffix\fP instead of the default \fB\.hxx\fP to construct the name of +the generated header file\. + +.IP "\fB--ixx-suffix\fP \fIsuffix\fP" +Use \fIsuffix\fP instead of the default \fB\.ixx\fP to construct the name of +the generated inline file\. + +.IP "\fB--cxx-suffix\fP \fIsuffix\fP" +Use \fIsuffix\fP instead of the default \fB\.cxx\fP to construct the name of +the generated source file\. + +.IP "\fB--man-suffix\fP \fIsuffix\fP" +Use \fIsuffix\fP instead of the default \fB\.1\fP to construct the name of +the generated man page file\. + +.IP "\fB--html-suffix\fP \fIsuffix\fP" +Use \fIsuffix\fP instead of the default \fB\.html\fP to construct the name +of the generated HTML file\. + +.IP "\fB--option-prefix\fP \fIprefix\fP" +Use \fIprefix\fP instead of the default \fB-\fP as an option prefix\. +Unknown command line arguments that start with this prefix are treated as +unknown options\. If you set the option prefix to the empty value, then all +the unknown command line arguments will be treated as program arguments\. + +.IP "\fB--option-separator\fP \fIsep\fP" +Use \fIsep\fP instead of the default \fB--\fP as an optional separator +between options and arguments\. All the command line arguments that are +parsed after this separator are treated as program arguments\. Set the +option separator to the empty value if you don't want this functionality\. + +.IP "\fB--include-with-brackets\fP" +Use angle brackets (<>) instead of quotes ("") in the generated +\fB#include\fP directives\. + +.IP "\fB--include-prefix\fP \fIprefix\fP" +Add \fIprefix\fP to the generated \fB#include\fP directive paths\. + +.IP "\fB--guard-prefix\fP \fIprefix\fP" +Add \fIprefix\fP to the generated header inclusion guards\. The prefix is +transformed to upper case and characters that are illegal in a preprocessor +macro name are replaced with underscores\. + +.IP "\fB--reserved-name\fP \fIname\fP=\fIrep\fP" +Add \fIname\fP with an optional \fIrep\fP replacement to the list of names +that should not be used as identifiers\. If provided, the replacement name +is used instead\. All C++ keywords are already in this list\. .\" .\" DIAGNOSTICS @@ -129,9 +176,7 @@ are already in this list. .SH DIAGNOSTICS If the input file is not a valid CLI definition, .B cli -will issue diagnostic messages to -.B STDERR -and exit with non-zero exit code. +will issue diagnostic messages to STDERR and exit with non-zero exit code. .\" .\" BUGS .\" diff --git a/doc/cli.xhtml b/doc/cli.xhtml index b026b6e..85dd4b9 100644 --- a/doc/cli.xhtml +++ b/doc/cli.xhtml @@ -59,81 +59,144 @@

DESCRIPTION

-

cli generates a C++ implementation for a command - line interface defined in the CLI language. For an input file in the - form name.cli the following C++ files are generated: +

cli generates C++ implementation and + documentation in various formats for a command line interface + defined in the CLI language. For an input file in the form + name.cli the following is generated. By + default or if the --generate-cxx option is + specified, the following C++ files are generated: name.hxx (header file), name.ixx (inline file, generated unless the --suppress-inline - option is specified), and name.cxx (source file).

+ option is specified), and name.cxx (source file). + If the --generate-html option is specified, then + the name.html HTML documentation file is generated. + If the --generate-man option is specified, then + the name.1 man page file is generated. When + --generate-html or --generate-man + is specified, the --stdout option can be used to + redirect the output to STDOUT instead of a file.

OPTIONS

-
-
--help
-
Print usage information and exit.
- -
--version
-
Print version and exit.
- -
--output-dir | -o dir
-
Write generated files to dir instead of - the current directory.
- -
--suppress-inline
-
Generate all functions non-inline. By default simple functions - are made inline. This option suppresses creation of the inline - file.
- -
--hxx-suffix suffix
-
Use the provided suffix instead of the default - .hxx to construct the name of the generated header - file.
- -
--ixx-suffix suffix
-
Use the provided suffix instead of the default - .ixx to construct the name of the generated inline - file.
- -
--cxx-suffix suffix
-
Use the provided suffix instead of the default - .cxx to construct the name of the generated source - file.
- -
--option-prefix prefix
-
Use the provided prefix instead of the default - - as an option prefix. Unknown command line - arguments that start with this prefix are treated as unknown options. - If you set the option prefix to the empty value, then all the unknown - command line arguments will be treated as program arguments.
- -
--option-separator separator
-
Use the provided separator instead of the default - -- as an optional separator between options and - arguments. All the command line arguments that are parsed after this - separator are treated as program arguments. Set the option separator - to the empty value if you don't want this functionality.
- -
--include-with-brackets
-
Use angle brackets (<>) instead of quotes ("") in generated - #include directives.
- -
--include-prefix prefix
-
Add prefix to generated #include - directive paths.
- -
--guard-prefix prefix
-
Add prefix to generated header inclusion guards. - The prefix is transformed to upper case and characters that are - illegal in a preprocessor macro name are replaced with underscores.
- -
--reserved-name name[=rep]
-
Add name to the list of names that should not - be used as identifiers. The name can optionally be followed by - = and the replacement name that should be - used instead. All C++ keywords are already in this list.
+ -
+
+
--help
+
Print usage information and exit.
+
--version
+
Print version and exit.
+ +
--output-dir|-o dir
+
Write the generated files to dir instead of the current directory.
+ +
--suppress-inline
+
Generate all functions non-inline. By default simple functions are made + inline. This option suppresses creation of the inline file.
+ +
--suppress-usage
+
Suppress the generation of the usage printing code.
+ +
--long-usage
+
If no short documentation string is provided, use the complete long + documentation string in usage. By default, in this situation only the first + sentence from the long string is used.
+ +
--option-length len
+
Indent option descriptions len characters when printing usage. This + is useful when you have multiple options classes, potentially in separate + files, and would like their usage to have the same indentation level.
+ +
--generate-cxx
+
Generate C++ code. If neither --generate-man nor + --generate-html is specified, this mode is assumed by + default.
+ +
--generate-man
+
Generate documentation in the man page format.
+ +
--generate-html
+
Generate documentation in the HTML format.
+ +
--man-prologue file
+
Insert the content of file at the beginning of the man page file.
+ +
--man-epilogue file
+
Insert the content of file at the end of the man page file.
+ +
--html-prologue file
+
Insert the content of file at the beginning of the HTML file.
+ +
--html-epilogue file
+
Insert the content of file at the end of the HTML file.
+ +
--class fq-name
+
Generate the man page or HTML documentation only for the fq-name + options class. The fq-name name should be a fully-qualified options + class name, for example, app::options. This + functionality is useful if you need to insert custom documentation between + options belonging to different classes.
+ +
--stdout
+
Write output to STDOUT instead of a file. This option is not valid when + generating C++ code and is normally used to combine generated documentation + for several option classes in a single file.
+ +
--hxx-suffix suffix
+
Use suffix instead of the default .hxx to + construct the name of the generated header file.
+ +
--ixx-suffix suffix
+
Use suffix instead of the default .ixx to + construct the name of the generated inline file.
+ +
--cxx-suffix suffix
+
Use suffix instead of the default .cxx to + construct the name of the generated source file.
+ +
--man-suffix suffix
+
Use suffix instead of the default .1 to construct + the name of the generated man page file.
+ +
--html-suffix suffix
+
Use suffix instead of the default .html to + construct the name of the generated HTML file.
+ +
--option-prefix prefix
+
Use prefix instead of the default - as an option + prefix. Unknown command line arguments that start with this prefix are + treated as unknown options. If you set the option prefix to the empty value, + then all the unknown command line arguments will be treated as program + arguments.
+ +
--option-separator sep
+
Use sep instead of the default -- as an optional + separator between options and arguments. All the command line arguments that + are parsed after this separator are treated as program arguments. Set the + option separator to the empty value if you don't want this functionality.
+ +
--include-with-brackets
+
Use angle brackets (<>) instead of quotes ("") in the generated + #include directives.
+ +
--include-prefix prefix
+
Add prefix to the generated #include directive + paths.
+ +
--guard-prefix prefix
+
Add prefix to the generated header inclusion guards. The prefix is + transformed to upper case and characters that are illegal in a preprocessor + macro name are replaced with underscores.
+ +
--reserved-name name=rep
+
Add name with an optional rep replacement to the list of names + that should not be used as identifiers. If provided, the replacement name is + used instead. All C++ keywords are already in this list.
+ +

DIAGNOSTICS

If the input file is not a valid CLI definition, cli diff --git a/doc/guide/index.xhtml b/doc/guide/index.xhtml index 24d76fa..a7ae6e7 100644 --- a/doc/guide/index.xhtml +++ b/doc/guide/index.xhtml @@ -125,6 +125,17 @@ padding : 0em 0 0em 0.7em; text-align : left; } + + /* Sample options documentation. */ + .options dt { + padding-top : 0.4em; + } + + .options dd { + padding-top : 0.1em; + padding-bottom : 0.4em; + padding-left : 1.4em; + } @@ -168,6 +179,7 @@ 2.2Translating CLI Definitions to C++ 2.3Implementing Application Logic 2.4Compiling and Running + 2.5Adding Documentation @@ -177,8 +189,9 @@ - - + + +
3.1Options Class Definition
3.2Option Definition
3.3Include Directive
3.4Namespace Definition
3.3Option Documentation
3.4Include Directive
3.5Namespace Definition
@@ -332,10 +345,9 @@ using namespace std; void usage () { - cerr << "usage: driver <options> <names>" << endl - << " [--help]" << endl - << " [--greeting <string>]" << endl - << " [--exclamations <integer>]" << endl; + cerr << "usage: driver [options] <names>" << endl + << "options:" << endl; + options::print_usage (cerr); } int @@ -411,19 +423,110 @@ Hi, Jane!!!

 $ ./driver -n 3 Jane
 unknown option '-n'
-usage: driver <options> <names>
-  [--help]
-  [--greeting <string>]
-  [--exclamations <integer>]
+usage: driver [options] <names>
+options:
+--help
+--greeting <arg>
+--exclamations <arg>
 
 $ ./driver --exclamations abc Jane
 invalid value 'abc' for option '--exclamations'
-usage: driver <options> <names>
-  [--help]
-  [--greeting <string>]
-  [--exclamations <integer>]
+usage: driver [options] <names>
+options:
+--help
+--greeting <arg>
+--exclamations <arg>
+  
+ +

2.5 Adding Documentation

+ +

As we have seen in the previous sections, the options + C++ class provides the print_usage() function which we + can use to display the application usage information. Right now this + information is very basic and does not include any description of + the purpose of each option:

+ +
+$ ./driver --help
+usage: driver [options] <names>
+options:
+--help
+--greeting <arg>
+--exclamations <arg>
+  
+ +

To make the usage information more descriptive we can document each + option in the command line interface definition. This information can + also be used to automatically generate program documentation in various + formats, such as HTML and man page. For example:

+ +
+include <string>;
+
+class options
+{
+  bool --help {"Print usage information and exit."};
+
+  std::string --greeting = "Hello"
+  {
+    "<text>",
+    "Use <text> as a greeting phrase instead of the default \"Hello\"."
+  };
+
+  unsigned int --exclamations = 1
+  {
+    "<num>",
+    "Print <num> exclamation marks instead of 1 by default."
+  };
+};
   
+

If we now save this updated command line interface to + hello.cli and recompile our application, the usage + information printed by the program will look like this:

+ +
+usage: driver [options] <names>
+options:
+--help               Print usage information and exit.
+--greeting <text>    Use <text> as a greeting phrase instead of the
+                     default "Hello".
+--exclamations <num> Print <num> exclamation marks instead of 1 by
+                     default.
+  
+ +

We can also generate the program documentation in the HTML + (--generate-html CLI option) and man page + (--generate-man CLI option) formats. For example:

+ +
+$ cli --generate-html hello.cli
+  
+ +

The resulting hello.html file contains the following + documentation:

+ +
+
--help
+
Print usage information and exit.
+ +
--greeting text
+
Use text as a greeting phrase instead of the default "Hello".
+ +
--exclamations num
+
Print num exclamation marks instead of 1 by default.
+ +
+ +

This HTML fragment can be combined with custom prologue and epilogue + to create a complete program documentation + (--html-prologue/--html-epilogue options for the HTML + output, --man-prologue/--man-epilogue options for the + man page output). For an example of such complete documentation see + the CLI + Compiler Command Line Manual and the cli(1) man + page. For more information on the option documentation syntax, + see Section 3.3, Option Documentation.

@@ -431,8 +534,8 @@ usage: driver <options> <names>

3 CLI Language

This chapter describes the CLI language and its mapping to C++. - A CLI file consists of zero or more Include - Directives followed by one or more Namespace Definitions + A CLI file consists of zero or more Include + Directives followed by one or more Namespace Definitions or Option Class Definitions. C and C++-style comments can be used anywhere in the CLI file except in character and string literals.

@@ -488,6 +591,10 @@ public: operator= (const options&); public: + static void + print_usage (std::ostream&); + +public: bool help () const; @@ -500,7 +607,10 @@ public:

An option class is mapped to a C++ class with the same name. The C++ class defines a set of public overloaded constructors, a public copy constructor and an assignment operator, as well as a set of public - accessor functions corresponding to option definitions.

+ accessor functions corresponding to option definitions. It also + defines a public static print_usage() function that + can be used to print the usage information for the options + defined by the class.

The argc/argv arguments in the overloaded constructors are used to pass the command line arguments array, normally as passed @@ -654,12 +764,12 @@ namespace cli

3.2 Option Definition

-

An option definition consists of there components: type, - name, and default value. An option type can be any - C++ type as long as its string representation can be parsed using - the std::istream interface. If the option type is - user-defined then you will need to include its declaration using - the Include Directive.

+

An option definition consists of four components: type, + name, default value, and documentation. + An option type can be any C++ type as long as its string representation + can be parsed using the std::istream interface. If the option + type is user-defined then you will need to include its declaration using + the Include Directive.

An option of a type other than bool is expected to have a value. An option of type bool is treated as @@ -672,7 +782,7 @@ namespace cli by |. The C++ accessor function name is derived from the first name by removing any leading special characters, such as -, /, etc., and replacing special characters - in other places with underscore. For example, the following option + in other places with underscores. For example, the following option definition:

@@ -705,7 +815,7 @@ class options
 };
   
-

The final component of the option definition is the optional default +

The following component of the option definition is the optional default value. If the default value is not specified, then the option is initialized with the default constructor. In particular, this means that a bool option will be initialized to false, @@ -797,7 +907,127 @@ class options -m =B (key is an empty string), -m c= (value is an empty string), or -m d (same as -m d=).

-

3.3 Include Directive

+

The last component in the option definition is optional documentation. + It is discussed in the next section.

+ +

3.3 Option Documentation

+ +

Option documentation mimics C++ string array initialization: + it is enclosed in {} and consists of one or more + documentation strings separated by a comma, for example:

+ +
+class options
+{
+  int --compression = 5
+  {
+    "<level>",
+    "Set compression to <level> instead of 5 by default.
+
+     With the higher compression levels the program may produce a
+     smaller output but may also take longer and use more memory."
+  };
+};
+  
+ +

The option documentation consists of a maximum of three documentation + strings. The first string is the value documentation string. + It describes the option value and is only applicable to options + with types other than bool (options of type + bool are flags and don't have an explicit value). + The second string (or the first string for options of type + bool) is the short documentation string. It + provides a brief description of the option. The last entry + in the option documentation is the long documentation string. + It provides a detailed description of the option. The short + documentation string is optional. If only two strings are + present in the option documentation (one string for options + of type bool), then the second (first) string is + assumed to be the long documentation string.

+ +

Option documentation is used to print the usage information + as well as to generate program documentation in the HTML and + man page formats. For usage information the short documentation + string is used if provided. If only the long string is available, + then, by default, only the first sentence from the long string + is used. You can override this behavior and include the complete + long string in the usage information by specifying the + --long-usage CLI compiler option. When generating + the program documentation, the long documentation strings are + always used.

+ +

The value documentation string can contain text enclosed in + <> which is automatically recognized by the CLI + compiler and typeset according to the selected output in all three + documentation strings. For example, in usage the level + value for the --compression option presented above + will be displayed as <level> while in the HTML and + man page output it will be typeset in italic as + level. Here is another example using the + std::map type:

+ +
+include <map>;
+include <string>;
+
+class options
+{
+  std::map<std::string, std::string> --map
+  {
+    "<key>=<value>",
+    "Add the <key>, <value> pair to the map."
+  };
+};
+  
+ +

The resulting HTML output for this option would look like this:

+ +
+
--map key=value
+
Add the key, value pair to the map.
+
+ +

As you might have noticed from the examples presented so far, the + documentation strings can span multiple lines which is not possible + in C++. Also, all three documentation strings support the following + basic formatting mechanisms. The start of a new paragraph is indicated + by a blank line. A fragment of text can be typeset in monospace font + (normally used for code fragments) by enclosing it in the + \c{} block. Similarly, text can be typeset in bold or + italic fonts using the \b{} and \i{} blocks, + respectively. You can also combine several font properties in a single + block, for example, \cb{bold code}. If you need to include + literal } in a formatting block, you can use the + \} escape sequence, for example, + \c{int a[] = {1, 2\}}. The following example shows how we + can use these mechanisms:

+ +
+class options
+{
+  int --compression = 5
+  {
+    "<level>",
+    "Set compression to <level> instead of 5 by default.
+
+     With the higher compression levels the program \i{may}
+     produce a smaller output but may also \b{take longer}
+     and \b{use more memory}."
+  };
+};
+  
+ +

The resulting HTML output for this option would look like this:

+ +
+
--compression level
+
Set compression to level instead of 5 by default. + +

With the higher compression levels the program may produce a + smaller output but may also take longer and use more memory.

+
+ +

3.4 Include Directive

If you are using user-defined types in your option definitions, you will need to include their declarations with the include @@ -843,7 +1073,7 @@ class options and name_type types in the options class would be undeclared and result in compilation errors.

-

3.4 Namespace Definition

+

3.5 Namespace Definition

Option classes can be placed into namespaces which are translated directly to C++ namespaces. For example:

diff --git a/doc/makefile b/doc/makefile index 7b97ba2..c9267a7 100644 --- a/doc/makefile +++ b/doc/makefile @@ -9,14 +9,32 @@ default := $(out_base)/ install := $(out_base)/.install cleandoc := $(out_base)/.cleandoc -$(default): $(out_base)/guide/ +$(default): $(out_base)/cli.xhtml $(out_base)/cli.1 $(out_base)/guide/ + +# Generated documentation. +# +$(out_base)/cli.xhtml: $(src_root)/cli/options.cli \ + $(src_base)/cli-prologue.xhtml \ + $(src_base)/cli-epilogue.xhtml + $(call message,cli-html $<,$(out_root)/cli/cli --generate-html \ +--output-dir $(out_base) --html-prologue $(src_base)/cli-prologue.xhtml \ +--html-epilogue $(src_base)/cli-epilogue.xhtml $<) + $(call message,,mv $(out_base)/options.html $(out_base)/cli.xhtml) + +$(out_base)/cli.1: $(src_root)/cli/options.cli \ + $(src_base)/cli-prologue.1 \ + $(src_base)/cli-epilogue.1 + $(call message,cli-man $<,$(out_root)/cli/cli --generate-man \ +--output-dir $(out_base) --man-prologue $(src_base)/cli-prologue.1 \ +--man-epilogue $(src_base)/cli-epilogue.1 $<) + $(call message,,mv $(out_base)/options.1 $(out_base)/cli.1) # Install. # -$(install): $(out_base)/guide/.install +$(install): $(out_base)/guide/.install $(out_base)/cli.xhtml $(out_base)/cli.1 $(call install-data,$(src_base)/default.css,$(install_doc_dir)/cli/default.css) - $(call install-data,$(src_base)/cli.xhtml,$(install_doc_dir)/cli/cli.xhtml) - $(call install-data,$(src_base)/cli.1,$(install_man_dir)/man1/cli.1) + $(call install-data,$(out_base)/cli.xhtml,$(install_doc_dir)/cli/cli.xhtml) + $(call install-data,$(out_base)/cli.1,$(install_man_dir)/man1/cli.1) # Clean. # -- cgit v1.1