adds a description of the command line interface to the documentation

This commit is contained in:
hneemann 2020-06-10 09:47:34 +02:00
parent d544fa06d7
commit 57d66f06ea
8 changed files with 140 additions and 22 deletions

View File

@ -68,14 +68,14 @@ public abstract class ArgumentBase<T> {
String s;
if (isBool())
s = "-" + getName()
+ "("
+ "(def: "
+ get()
+ ")";
else
s = "-" + getName()
+ " ["
+ get().getClass().getSimpleName()
+ "("
+ "(def: "
+ get()
+ ")]";

View File

@ -7,7 +7,9 @@ package de.neemann.digital.cli.cli;
import de.neemann.digital.lang.Lang;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@ -65,7 +67,32 @@ public abstract class BasicCommand extends NamedCommand {
out.print(prefix + " ");
printString(out, prefix + " ", a.getDescription(getName()));
}
}
@Override
public void printXMLDescription(Writer w) throws IOException {
w.write("<indent>\n");
w.append(getName());
for (ArgumentBase<?> a : arguments) {
w.append(" ");
w.append(a.toString());
}
w.append(":");
w.write("<indent>\n");
w.write(Lang.get("cli_help_" + getName()));
w.write("</indent>\n");
w.write("<indent>\n");
w.write(Lang.get("cli_options"));
for (ArgumentBase<?> a : arguments) {
w.write("<indent>\n");
w.write(a.toStringDef());
w.write("<indent>\n");
w.write(a.getDescription(getName()));
w.write("</indent>\n");
w.write("</indent>\n");
}
w.write("</indent>\n");
w.write("</indent>\n");
}
void printString(PrintStream out, String prefix, String message) {

View File

@ -5,27 +5,38 @@
*/
package de.neemann.digital.cli.cli;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Writer;
/**
* A cli command
*/
public interface CLICommand {
/**
* Executes the command
*
* @param args the arguments
* @throws CLIException CLIException
*/
void execute(String[] args) throws CLIException;
/**
* Prints the description
*
* @param out the pront stream
* @param out the print stream
* @param prefix the prefex string which should
* printed at the beginning of each line
*/
void printDescription(PrintStream out, String prefix);
/**
* Esecuted the command
* Prints the description in xml format
*
* @param args the arguments
* @throws CLIException CLIException
* @param w the writer to write to
* @throws IOException IOException
*/
void execute(String[] args) throws CLIException;
void printXMLDescription(Writer w) throws IOException;
}

View File

@ -7,7 +7,9 @@ package de.neemann.digital.cli.cli;
import de.neemann.digital.lang.Lang;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
@ -58,6 +60,15 @@ public class Muxer extends NamedCommand {
c.printDescription(out, prefix + " ");
}
@Override
public void printXMLDescription(Writer w) throws IOException {
w.write("<indent>\n");
w.write(getName());
for (CLICommand c : commands.values())
c.printXMLDescription(w);
w.write("</indent>\n");
}
@Override
public void execute(String[] args) throws CLIException {
if (args.length == 0)

View File

@ -1541,6 +1541,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="lib_ram">RAM</string>
<string name="lib_eeprom">EEPROM</string>
<string name="cli_cli">Steuerung per Kommandozeile</string>
<string name="cli_nonOptionalArgumentMissing_N">Es fehlt das nicht optionale Argument {0}.</string>
<string name="cli_notABool_N">Der Wert {0} ist kein bool.</string>
<string name="cli_notANumber_N">Der Wert {0} ist keine Zahl.</string>
@ -1572,7 +1573,9 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
Aufgeführt sind alle verwendeten Komponenten.
</string>
<string name="cli_help_stats_dig">Name der Schaltung.</string>
<string name="cli_help_stats_csv">Name der Ausgabedatei.</string>
<string name="cli_help_stats_csv">Name der Ausgabedatei.
Wenn diese Option fehlt, erfolgt eine Ausgabe auf die Konsole.
</string>
<string name="cli_errorCreatingStats">Fehler bei der Erzeugung der CSV Datei!</string>
<string name="menu_window">Fenster</string>

View File

@ -1505,6 +1505,7 @@
<string name="lib_ram">RAM</string>
<string name="lib_eeprom">EEPROM</string>
<string name="cli_cli">Command Line Interface</string>
<string name="cli_nonOptionalArgumentMissing_N">The non-optional argument {0} is missing.</string>
<string name="cli_notABool_N">The value {0} is no bool.</string>
<string name="cli_notANumber_N">The value {0} is not a number.</string>
@ -1534,7 +1535,9 @@
All components used are listed in the CSV file.
</string>
<string name="cli_help_stats_dig">File name of the circuit.</string>
<string name="cli_help_stats_csv">Name of the csv file to be created.</string>
<string name="cli_help_stats_csv">Name of the csv file to be created.
If this option is missing, the table is written to stdout.
</string>
<string name="cli_errorCreatingStats">Error while creating the stats file!</string>
<string name="menu_window">Windows</string>

View File

@ -5,6 +5,7 @@
*/
package de.neemann.digital.docu;
import de.neemann.digital.cli.Main;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.*;
import de.neemann.digital.draw.elements.PinException;
@ -89,6 +90,8 @@ public class DocuTest extends TestCase {
w.append(" </circuit>\n");
w.append(" </settings>\n");
writeCLIDescription(w);
ElementLibrary library = new ElementLibrary();
ShapeFactory shapeFactory = new ShapeFactory(library, !language.equals("de"));
String actPath = null;
@ -139,6 +142,12 @@ public class DocuTest extends TestCase {
w.append("</root>");
}
private void writeCLIDescription(Writer w) throws IOException {
w.append(" <cli heading=\"").append(Lang.get("cli_cli")).append("\">\n");
new Main().printXMLDescription(w);
w.append(" </cli>\n");
}
private void writeAttributes(Writer w, List<Key> keyList) throws IOException {
w.append(" <attributes name=\"").append(Lang.get("elem_Help_attributes")).append("\">\n");
for (Key k : keyList) {

View File

@ -78,43 +78,86 @@
<fo:block page-break-before="always" margin-bottom="5mm" font-size="18pt" font-weight="bold">
<xsl:value-of select="@toc"/>
</fo:block>
<!-- table of contents -->
<!-- table of contents -->
<fo:block margin-bottom="2mm" font-weight="bold">
A <fo:inline padding-left="1mm"><xsl:value-of select="@general"/></fo:inline>
A
<fo:inline padding-left="1mm">
<xsl:value-of select="@general"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="document(@static)/*" mode="toc"/>
<fo:block margin-top="2mm" margin-bottom="2mm" font-weight="bold">
<fo:basic-link show-destination="replace" internal-destination="chap_settings">
B <fo:inline padding-left="2mm"><xsl:value-of select="settings/@name"/></fo:inline>
B
<fo:inline padding-left="2mm">
<xsl:value-of select="settings/@name"/>
</fo:inline>
</fo:basic-link>
</fo:block>
<fo:block margin-top="2mm" margin-bottom="2mm" font-weight="bold">
C <fo:inline padding-left="2mm"><xsl:value-of select="@components"/></fo:inline>
<fo:basic-link show-destination="replace" internal-destination="chap_cli">
C
<fo:inline padding-left="2mm">
<xsl:value-of select="cli/@heading"/>
</fo:inline>
</fo:basic-link>
</fo:block>
<fo:block margin-top="2mm" margin-bottom="2mm" font-weight="bold">
D
<fo:inline padding-left="2mm">
<xsl:value-of select="@components"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="lib" mode="toc"/>
<fo:block margin-top="2mm" margin-bottom="2mm" font-weight="bold">
<fo:basic-link show-destination="replace" internal-destination="chap_library">
D <fo:inline padding-left="2mm"><xsl:value-of select="@lib"/></fo:inline>
E
<fo:inline padding-left="2mm">
<xsl:value-of select="@lib"/>
</fo:inline>
</fo:basic-link>
</fo:block>
<fo:block page-break-before="always"/>
<!-- the content -->
<fo:block margin-top="4mm" margin-bottom="4mm" font-size="16pt" font-weight="bold">
A <fo:inline padding-left="2mm"><xsl:value-of select="@general"/></fo:inline>
A
<fo:inline padding-left="2mm">
<xsl:value-of select="@general"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="document(@static)/*" mode="full"/>
<fo:block page-break-before="always" margin-top="4mm" margin-bottom="4mm" font-size="16pt" font-weight="bold" id="chap_settings">
B <fo:inline padding-left="2mm"><xsl:value-of select="settings/@name"/></fo:inline>
<fo:block page-break-before="always" margin-top="4mm" margin-bottom="4mm" font-size="16pt"
font-weight="bold" id="chap_settings">
B
<fo:inline padding-left="2mm">
<xsl:value-of select="settings/@name"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="settings" mode="full"/>
<fo:block page-break-before="always" margin-top="4mm" margin-bottom="4mm" font-size="16pt"
font-weight="bold" id="chap_cli">
C
<fo:inline padding-left="2mm">
<xsl:value-of select="cli/@heading"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="cli" mode="full"/>
<fo:block page-break-before="always" margin-bottom="4mm" font-size="16pt" font-weight="bold">
C <fo:inline padding-left="2mm"><xsl:value-of select="@components"/></fo:inline>
D
<fo:inline padding-left="2mm">
<xsl:value-of select="@components"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="lib" mode="full"/>
<fo:block page-break-before="always" margin-bottom="4mm" font-size="16pt" font-weight="bold" id="chap_library">
D <fo:inline padding-left="2mm"><xsl:value-of select="@lib"/></fo:inline>
<fo:block page-break-before="always" margin-bottom="4mm" font-size="16pt" font-weight="bold"
id="chap_library">
E
<fo:inline padding-left="2mm">
<xsl:value-of select="@lib"/>
</fo:inline>
</fo:block>
<xsl:apply-templates select="document(@library)/*"/>
<fo:block id="LastPage"/>
@ -294,14 +337,25 @@
<xsl:apply-templates select="circuit/attributes"/>
</xsl:template>
<xsl:template match="cli" mode="full">
<xsl:apply-templates select="indent"/>
</xsl:template>
<xsl:template match="indent">
<fo:block margin-left="4mm" start-indent="2mm" margin-top="2mm" margin-bottom="2mm">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="lib" mode="full">
<fo:block page-break-after="avoid" margin-top="4mm" margin-bottom="4mm" font-size="16pt" font-weight="bold">
<xsl:value-of select="position()"/>. <xsl:value-of select="@name"/>
<xsl:value-of select="position()"/>.
<xsl:value-of select="@name"/>
</fo:block>
<xsl:apply-templates select="element" mode="full">
<xsl:with-param name="number" select="position()"/>
</xsl:apply-templates>
</xsl:template>
</xsl:template>
<xsl:template match="element" mode="full">
<xsl:param name="number" />