felix rosencrantz | Generating Larch Completion |
what |
Attempt to show that the xml format is useful
for generating a completion function for a command that has subcommands
(like the commands for many SCM systems). This attempt is to generate
a completion function for Tom Lord's
arch revision control system. This is based on version
arch-1.0-pre9. Earlier I attempted a similar project for the clearcase command set, before I had the simple format. The attempt for larch was much easier. However, the _larch completion function doesn't properly complete argument positions. |
step 1 |
First get the help information: larch --help-commands > larch-help-commands |
step 2 | Get the names and descriptions of the
subcommands. Store the results in an associative array. The help file format is "word : help text", there are other lines in the help output that group the commands by function, the grep command pulls out subcommands. The sed command makes sure the help text is quoted. The typeset command makes fuz an associative array. The (fz) modifiers on lhz break the value of lhc on lines, and then into command and help. So that fuz has the subcommands as keys and the help text as values. lhc=("$(grep " : " larch-help-commands | sed -e
's/: /"/' -e 's/$/"/')")
|
step 3 | Build simple.xml files per each subcommand. For each subcommand (the keys of fuz), get the help output for that subcommand from larch (larch $c -h). Then using perl modify the output so that it works with help2simple.pl. Help2simple.pl expects that when you have single&multi-letter flags that take an argument both flags have the argument. The perl script handles that. The help2simple.pl flag "is-subcommand" causes the XML output to be in the format of a subcommand. The "subcommand-descr" flag sets the description for the subcommand pulled from the fuz . (The (Q) operator removes quotes added earlier. Put the output in the subcmds directory. mkdir subcmds |
step 4 | Now build the simple.xml for the larch command.
Including the xml files for the subcommands. Now generate the full simple xml file. Get help from "larch -h". The "has-subcommands" flag says that larch has subcommands, and the subcommand parts can be found in all the xml files in the subcmd directory. The subcommand files are just included without processing, so they should be in a format that fits without causing parsing problems. larch -h |\ |
step 5 | Perform the XML transformations via XSLT.
The _larch file can be place in a directory on your $fpath.
java com.icl.saxon.StyleSheet fu.xml
simple2long.xsl >! long.xml |
final |
So I added a couple of new flags to
help2simple.pl to allow for the generation of subcommands, and building a
command that has subcommands. One area that still is fairly weak is dealing with the regular arguments to a command. Also, the ability to make parsing customizations. The generated _larch file and the latest version of the scripts used above can be found in release tar. |
Web site Copyright © 2001 Felix Rosencrantz, f_rosencrantz@yahoo.com |