SimpleProgram v1.0 

 The Simple Development Library program declaration 

Project: the Simple Development Library.

Table of contents

1. Package description
   1.1 Overview
   1.2 Usage
   1.3 Examples
   1.4 History
   1.5 Copyright
2. Package public API
   2.1 Types
   2.2 Options
   2.3 Namespaces
   2.4 Commands
      2.4.1 ::Simple::Program::cget
      2.4.2 ::Simple::Program::configure
      2.4.3 declare-program program ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-exitstatus string? ?-help string? ?-keywords list? ?-examples string? ?-error declaration? ?-type declaration? ?-variable declaration? ?-command declaration? ?-option declaration? ?-optionsusage list? ?-requisites packagerequisite-list? ?-assumptions string? ?-resources string? ?-limitations string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-cmid string? ?-sprs string? ?-smrs string? ?-history string? ?-copyright string? ?-body script?
      2.4.4 ::Simple::Program::die ?-trymessage? message ?status?
      2.4.5 ::Simple::Program::information commands
      2.4.6 ::Simple::Program::information errors
      2.4.7 ::Simple::Program::information examples
      2.4.8 ::Simple::Program::information help
      2.4.9 ::Simple::Program::information metadata
      2.4.10 ::Simple::Program::information name
      2.4.11 ::Simple::Program::information options
      2.4.12 ::Simple::Program::information requisites
      2.4.13 ::Simple::Program::information synopsis
      2.4.14 ::Simple::Program::information types
      2.4.15 ::Simple::Program::information variables
      2.4.16 ::Simple::Program::information version
      2.4.17 ::Simple::Program::parse-command-line commandLine
   2.5 Errors
3. Package further information
4. Package command details
   4.1 ::Simple::Program::cget
      4.1.1 Command description
      4.1.2 Command public API
   4.2 ::Simple::Program::configure
      4.2.1 Command description
      4.2.2 Command public API
   4.3 declare-program program ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-exitstatus string? ?-help string? ?-keywords list? ?-examples string? ?-error declaration? ?-type declaration? ?-variable declaration? ?-command declaration? ?-option declaration? ?-optionsusage list? ?-requisites packagerequisite-list? ?-assumptions string? ?-resources string? ?-limitations string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-cmid string? ?-sprs string? ?-smrs string? ?-history string? ?-copyright string? ?-body script?
      4.3.1 Command description
         4.3.1.1 Overview
      4.3.2 Command public API
      4.3.3 Command further information
         4.3.3.1 Remarks
   4.4 ::Simple::Program::die ?-trymessage? message ?status?
      4.4.1 Command description
         4.4.1.1 Overview
      4.4.2 Command public API
   4.5 ::Simple::Program::information commands
      4.5.1 Command description
      4.5.2 Command public API
   4.6 ::Simple::Program::information errors
      4.6.1 Command description
      4.6.2 Command public API
   4.7 ::Simple::Program::information examples
      4.7.1 Command description
      4.7.2 Command public API
   4.8 ::Simple::Program::information help
      4.8.1 Command description
      4.8.2 Command public API
   4.9 ::Simple::Program::information metadata
      4.9.1 Command description
         4.9.1.1 Overview
      4.9.2 Command public API
   4.10 ::Simple::Program::information name
      4.10.1 Command description
      4.10.2 Command public API
   4.11 ::Simple::Program::information options
      4.11.1 Command description
      4.11.2 Command public API
   4.12 ::Simple::Program::information requisites
      4.12.1 Command description
      4.12.2 Command public API
   4.13 ::Simple::Program::information synopsis
      4.13.1 Command description
      4.13.2 Command public API
   4.14 ::Simple::Program::information types
      4.14.1 Command description
      4.14.2 Command public API
   4.15 ::Simple::Program::information variables
      4.15.1 Command description
      4.15.2 Command public API
   4.16 ::Simple::Program::information version
      4.16.1 Command description
      4.16.2 Command public API
   4.17 ::Simple::Program::parse-command-line commandLine
      4.17.1 Command description
         4.17.1.1 Overview
      4.17.2 Command public API
      4.17.3 Command further information
         4.17.3.1 References

1. Package description

Synopsis: the Simple Development Library program declaration.

Keywords: program, declaration and command line.

1.1 Overview

This package provides a way to declare programs in an homogeneous, easily parseable, fully introspectable way. It allows to substitute the comment block which is usually placed at the beginning of each program file by Tcl-handled text.

Programs are declared with a single command (declare-program). Every single component needed to either make the program work (such as the program options) or to document it (metadata, such as the program synopsis) is provided as arguments to that command. Components can be fully introspected, but metadata is only available if The Simple Development Library -storemetadata option is set when the program is declared.

Procedures are provided to declare a program, get information about the program, parse the program command line and exit the program execution.

1.2 Usage

Use declare-program to declare a program. The declared program metadata given to declare-program (or composed from other data, if not given, as for --help) can be obtained via the ::Simple::Program::information metadata procedure. Other subcommands of this procedure provide information about a declared program: name, version, requisites, synopsis, help, examples, options, errors, variables, types and commands.

Use ::Simple::Program::parse-command-line to parse the program command line arguments and ::Simple::Program::die to display an error and exit.

There is a backdoor implemented which allows to display the error stack trace held in errorInfo upon an uncatched error in the program execution: give the --errorinfo option as a command line argument.

1.3 Examples

1.4 History

Date Reason
23-apr-2000 First public release, version 0.2
10-sep-2001 Second public release, version 0.4
17-feb-2003 Third public release, version 0.5
05-apr-2003 Added -body to declare-program, version 0.5.1
27-apr-2003 Added -command to declare-program and added ::Simple::Program::information metadata, version 0.5.2
01-may-2003 Extra package, version 0.5.3
20-jan-2004 Comments allowed before embedded declarations in declare-program version 0.5.4
22-jun-2005 The Simple Development Library version 1.0

1.5 Copyright

Copyright (C) 1999-2005, Juan C. Gil (jgil@gmv.es).

2. Package public API

Paradigm: procedural.

Requisites: SimpleOption 1.0.

2.1 Types

None.

2.2 Options

None.

2.3 Namespaces

  1. ::Simple::Program

  2. ::Simple::Program::Priv

2.4 Commands

2.4.1 ::Simple::Program::cget

Synopsis: gets the package options.

Details: see section 4.1.

2.4.2 ::Simple::Program::configure

Synopsis: configures the package options.

Details: see section 4.2.

2.4.3 declare-program program ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-exitstatus string? ?-help string? ?-keywords list? ?-examples string? ?-error declaration? ?-type declaration? ?-variable declaration? ?-command declaration? ?-option declaration? ?-optionsusage list? ?-requisites packagerequisite-list? ?-assumptions string? ?-resources string? ?-limitations string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-cmid string? ?-sprs string? ?-smrs string? ?-history string? ?-copyright string? ?-body script?

Synopsis: declares a program.

Details: see section 4.3.

2.4.4 ::Simple::Program::die ?-trymessage? message ?status?

Synopsis: displays an error message and exits unssuccessfully.

Details: see section 4.4.

2.4.5 ::Simple::Program::information commands

Synopsis: returns the program commands.

Details: see section 4.5.

2.4.6 ::Simple::Program::information errors

Synopsis: returns the program errors.

Details: see section 4.6.

2.4.7 ::Simple::Program::information examples

Synopsis: returns the program examples.

Details: see section 4.7.

2.4.8 ::Simple::Program::information help

Synopsis: returns the program help message.

Details: see section 4.8.

2.4.9 ::Simple::Program::information metadata

Synopsis: returns the program metadata.

Details: see section 4.9.

2.4.10 ::Simple::Program::information name

Synopsis: returns the program name.

Details: see section 4.10.

2.4.11 ::Simple::Program::information options

Synopsis: returns the program options.

Details: see section 4.11.

2.4.12 ::Simple::Program::information requisites

Synopsis: returns the program requisites.

Details: see section 4.12.

2.4.13 ::Simple::Program::information synopsis

Synopsis: returns the program synopsis.

Details: see section 4.13.

2.4.14 ::Simple::Program::information types

Synopsis: returns the program types.

Details: see section 4.14.

2.4.15 ::Simple::Program::information variables

Synopsis: returns the program variables.

Details: see section 4.15.

2.4.16 ::Simple::Program::information version

Synopsis: returns the program version.

Details: see section 4.16.

2.4.17 ::Simple::Program::parse-command-line commandLine

Synopsis: parses a program command line.

Details: see section 4.17.

2.5 Errors

None.

3. Package further information

None.

4. Package command details

4.1 ::Simple::Program::cget

4.1.1 Command description

Synopsis: gets the package options.

Access mode: public.

4.1.2 Command public API

Arguments: none.

Returns: the requested option value or the whole list of options if none specified.

4.2 ::Simple::Program::configure

4.2.1 Command description

Synopsis: configures the package options.

Access mode: public.

4.2.2 Command public API

Arguments: none.

Returns: the "package with no options" error is thrown.

4.3 declare-program program ?-version version? ?-project string? ?-synopsis string? ?-overview string? ?-usage string? ?-exitstatus string? ?-help string? ?-keywords list? ?-examples string? ?-error declaration? ?-type declaration? ?-variable declaration? ?-command declaration? ?-option declaration? ?-optionsusage list? ?-requisites packagerequisite-list? ?-assumptions string? ?-resources string? ?-limitations string? ?-details string? ?-references string? ?-remarks string? ?-todo string? ?-cmid string? ?-sprs string? ?-smrs string? ?-history string? ?-copyright string? ?-body script?

(Alias for ::Simple::Program::declare).

4.3.1 Command description

Synopsis: declares a program.

Access mode: public.

4.3.1.1 Overview

This procedure provides a way to declare a program. This procedure can be invoked just once.

The -synopsis flag is mandatory.

The -option flag allows to declare the program command line options. Its argument is an option declaration intended to be the arguments of a call to the ::Simple::Option::declare procedure. This flag can be given multiple times. The command line options actually accepted by the program include those plus --help, --version and --examples (as well as the backdoor option --errorinfo); see the ::Simple::Program::parse-command-line procedure.

If -optionsusage is given, the options usage is declared via the ::Simple::Option::declare-usage procedure.

If -requisites is given, the program requisites are required and installed via the ::Simple::Package::require-and-install procedure.

If -help is given, its argument is the help message displayed when invoking the program with the --help option, after substituting the %USAGE%, %SYNOPSIS% and %OPTIONS% strings by the program usage, the program synopsis or the detailed options explanation, respectively. Otherwise the help message is composed from the synopsis and options information.

The -command flag allows to declare program commands. Its argument is a command declaration intended to be the arguments of a call to ::Simple::Declare::declare-proc. This flag can be given multiple times. Program commands are intended as helper procedures for the program. In principle, program commands should live in the global namespace, but this is currently not enforced.

The -error flag allows to declare program errors. Its argument is an error declaration intended to be the arguments of a call to ::Simple::Error::declare. This flag can be given multiple times.

The -type flag allows to declare program types. Its argument is a type declaration intended to be the arguments of a call to ::Simple::Type::declare. This flag can be given multiple times.

The -variable flag allows to create program variables. Its argument is a variable declaration intended to be the arguments of a call to ::Simple::Variable::declare. This flag can be given multiple times.

It is not allowed to declare program classes. Place the classes in a package and require that package instead.

The mandatory -body flag specifies the program body script. This script is evaluated in the global scope. If there is an error in the evaluation, ::Simple::Program::die is invoked with the error message as argument. Otherwise, the program exits with exit status equal to zero. If other exit status and/or other behaviour is needed, use either exit or ::Simple::Program::die in the program body script. Notice that -exitstatus is just a documentation flag.

All other arguments are metadata, and are stored or ignored depending on whether The Simple Development Library -storemetadata option is set when the program is declared, but for the -body flag which is never stored.

4.3.2 Command public API

Arguments: (flag parsing disabled)

Argument Type Default value/ choices Description
program unqualifiedname (n/a) Program name
?-version? version 1.0 Program version
?-project? string (empty string) Program project
?-synopsis? string (empty string) Program synopsis
?-overview? string (empty string) Program overview
?-usage? string (empty string) Program usage message
?-exitstatus? string (empty string) Program exit status
?-help? string (n/a) Program command line help message
?-keywords? list (empty string) Program keywords
?-examples? string (empty string) Program usage examples
?-error? declaration (empty string) Program error declaration
?-type? declaration (empty string) Program type declaration
?-variable? declaration (empty string) Program variable declaration
?-command? declaration (empty string) Program command declaration
?-option? declaration (empty string) Program command line option declaration
?-optionsusage? list (empty string) Program command line options usage
?-requisites? packagerequisite-list (empty string) Program requisites
?-assumptions? string (empty string) Program assumptions
?-resources? string (empty string) Program required resources
?-limitations? string (empty string) Program limitations
?-details? string (empty string) Program implementation details
?-references? string (empty string) Program references
?-remarks? string (empty string) Program remarks
?-todo? string (empty string) Program to do list
?-cmid? string (empty string) Program configuration management identification
?-sprs? string (empty string) Program software problem reports
?-smrs? string (empty string) Program software modification reports
?-history? string (empty string) Program history
?-copyright? string (empty string) Program copyright notice
?-body? script (empty string) Program body

Returns: the empty string.

Effects:

4.3.3 Command further information

4.3.3.1 Remarks

4.4 ::Simple::Program::die ?-trymessage? message ?status?

4.4.1 Command description

Synopsis: displays an error message and exits unssuccessfully.

Access mode: public.

4.4.1.1 Overview

This procedure displays an error message in the standard error channel and exists the program. If the -trymessage flag is given, the try message ("Try <program name --help> for more information") is also displayed.

4.4.2 Command public API

Arguments:

Argument Type Default value/ choices Description
-trymessage boolflag (n/a) Whether to display the try message
message string (n/a) Error message
?status? integer 1 Exit status

Returns: none; the program is finished.

Effects:

4.5 ::Simple::Program::information commands

4.5.1 Command description

Synopsis: returns the program commands.

Access mode: public.

4.5.2 Command public API

Arguments: none.

Returns: the program commands.

4.6 ::Simple::Program::information errors

4.6.1 Command description

Synopsis: returns the program errors.

Access mode: public.

4.6.2 Command public API

Arguments: none.

Returns: the program errors.

4.7 ::Simple::Program::information examples

4.7.1 Command description

Synopsis: returns the program examples.

Access mode: public.

4.7.2 Command public API

Arguments: none.

Returns: the program examples.

4.8 ::Simple::Program::information help

4.8.1 Command description

Synopsis: returns the program help message.

Access mode: public.

4.8.2 Command public API

Arguments: none.

Returns: the program help message .

4.9 ::Simple::Program::information metadata

4.9.1 Command description

Synopsis: returns the program metadata.

Access mode: public.

4.9.1.1 Overview

This procedure returns a list of pairs suitable to be given as argument to the array set command. Each element is one of the flags given to declare-program upon program declaration (with no hypen), but for -body (which is not stored), the item declarations (-error, -type, -variable, -command and -option; these are obtained using the corresponding ::Simple::Program::information subcommand), the -optionsusage flag (use ::Simple::Option::information usage to get this one) and -version, -synopsis, -help, -examples, -requisites and -name for which specific ::Simple::Program::information subcommands exists.

Thus, the actual list of flags is: -project, -overview, -usage, -exitstatus, -keywords, -assumptions, -resources, -limitations, -details, -references, -remarks, -todo, -cmid, -sprs, -smrs, -history and -copyright.

Notice that no data is returned unless The Simple Development Library -storemetadata option is set when the program was declared.

If a particular flag was not given in the program declaration, the empty string is returned as that flag contents.

4.9.2 Command public API

Arguments: none.

Returns: the program metadata as an item/contents pairs list.

4.10 ::Simple::Program::information name

4.10.1 Command description

Synopsis: returns the program name.

Access mode: public.

4.10.2 Command public API

Arguments: none.

Returns: the program name.

4.11 ::Simple::Program::information options

4.11.1 Command description

Synopsis: returns the program options.

Access mode: public.

4.11.2 Command public API

Arguments: none.

Returns: the program options.

4.12 ::Simple::Program::information requisites

4.12.1 Command description

Synopsis: returns the program requisites.

Access mode: public.

4.12.2 Command public API

Arguments: none.

Returns: the program requisites.

4.13 ::Simple::Program::information synopsis

4.13.1 Command description

Synopsis: returns the program synopsis.

Access mode: public.

4.13.2 Command public API

Arguments: none.

Returns: the program synopsis.

4.14 ::Simple::Program::information types

4.14.1 Command description

Synopsis: returns the program types.

Access mode: public.

4.14.2 Command public API

Arguments: none.

Returns: the program types.

4.15 ::Simple::Program::information variables

4.15.1 Command description

Synopsis: returns the program variables.

Access mode: public.

4.15.2 Command public API

Arguments: none.

Returns: the program variables.

4.16 ::Simple::Program::information version

4.16.1 Command description

Synopsis: returns the program version.

Access mode: public.

4.16.2 Command public API

Arguments: none.

Returns: the program version.

4.17 ::Simple::Program::parse-command-line commandLine

4.17.1 Command description

Synopsis: parses a program command line.

Access mode: public.

4.17.1.1 Overview

This procedure is similar to the ::Simple::Option::parse procedure in that it parses the program command line and assesses its compliance against the program options and their usage. If an error is found when parsing the command line, a suitable diagnostics is displayed in the standard error channel together with a message sugesting the use of the --help option, and the program exits.

On top of the program options given as parameter to the -option flag in the call to declare-program, this procedure also accepts the --help, --version, --examples and --errorinfo command line options:

--help

--version

--examples

--errorinfo

4.17.2 Command public API

Arguments:

Argument Type Default value/ choices Description
commandLine list (n/a) Program command line arguments

Returns: the empty string.

Effects:

4.17.3 Command further information

4.17.3.1 References