felix rosencrantz help2simple.pl
introduction
The help2simple.pl script is designed to make it easy to take usage information from a command and convert that into the simple XML completion format.  Which via XSL can be converted to zsh completion functions.
process
The process you use to get a completion function is as follows.
  1. Save the help output from a command.
    • cmd --help > help 2>&1
  2. Perform any necessary editing to get the output in a format that help2simple.pl wants:
    • A tab or two plus spaces after a flag's argument, before the help.
    • A comma or the word "or" between alternate forms of the same flag. (e.g. "-h or --help).
  3. Run the help2simple.pl command, which will attempt to parse the help output, and create an XML representation of the help.  The XML format is the "simple" format (as opposed to the long format...)
    • help2simple.pl -c cmd < help > simple.xml
  4. Repeat previous step as much as needed, add additional command line flags to help2simple.pl.
  5. Run the simple.xml file through the simple2long.xsl XSLT script.  This converts the simple format to the long format.  Use your favorite XSLT 1.1 processor like jd.xslt or saxon.
    • xslt simple.xml simple2long.xsl > long.xml
  6. Generate the cmd_defines.xml file.  This file is used to map flag arguments to commands or states.
    • xslt long.xml gen_comdefs.xsl unique_actions.xsl > cmd_defines.xml
  7. Edit the cmd_defines.xml to specify the actions for a given
  8. Run the long.xml through arg.xsl, and you get a completion function
    • xslt long.xml arg.xsl > _cmd
  9. You may have to hand edit the _cmd script, but as it stands, it should be a reasonable start.
files
file (html) Original
help2simple.pl help2simple.pl
simple2long.xsl simple2long.xsl
gen_comdefs.xsl gen_comdefs.xsl
unique_actions.xsl unique_actions.xsl
arg.xsl arg.xsl
related
Related tools:

help2man -- A perl script that parses help output to create a man page.  This script handles flag help text spans multiple lines.  It also parses out the leading usage message, and section titles.  Some of these features would be useful to add to help2simple.pl.

Getopt::Declare Declaratively Expressed Command-Line Arguments via Regular Expressions.  With this perl module the user specifies getopt via a help syntax.  I haven't used this module.  Though it seems, that the help has to be in the special format, which is relatively free format.  It would be great if this library could output a data structure that could be used by help2simple.pl

parse_opts Arguments processing tool by Martin Ebourne.  Designed as both a completion tool and the command line parsing tool.


Web site Copyright ©  2001 Felix Rosencrantz, f_rosencrantz@yahoo.com