Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kommandozeilentool

Kommandos

Kommando: importStammdaten

Beschreibung

Import der Stammdaten (JSON files).

Parameter

targetDir (Hauptargument): Verzeichnis der zu importierenden Dateien

  • encoding: Encoding der Dateien
  • filter: Dateinamenfilter

Beispielaufruf

docker exec client run importStammdaten \
    -encoding <value> \
    -filter <value>\
    <targetDir>
import com.beust.jcommander.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
public class MarkdownUsageFormatter implements IUsageFormatter {
private final JCommander commander;
public MarkdownUsageFormatter(JCommander commander) {
this.commander = commander;
}
public final void usage(String commandName) {
StringBuilder sb = new StringBuilder();
this.usage(commandName, sb);
}
public final void usage(String commandName, StringBuilder out) {
this.usage(commandName, out, "");
}
public final void usage(StringBuilder out) {
this.usage(out, "");
try {
Files.write(Paths.get("cli.md"), out.toString().getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void usage(String s, StringBuilder stringBuilder, String s1) {
usage(stringBuilder, s1);
}
public void usage(StringBuilder out, String indent) {
commander.getFields().forEach(
(k, v) -> out.append("- **")
.append(k.getName())
.append("**: ")
.append(v.getDescription())
.append("\n")
);
out.append("\n\n").append("## Kommandos\n");
for (String c : commander.getCommands().keySet()) {
out.append("\n### Kommando: **").append(c).append("**\n").append("#### Beschreibung").append("\n\n");
JCommander command = commander.getCommands().get(c);
out.append(new DefaultUsageFormatter(commander).getCommandDescription(c)).append("\n\n");
out.append("#### Parameter\n\n");
String name = command.getMainParameterValue().getParameterized().getName();
if (command.getMainParameter() != null) {
out.append("**").append(name).append("** (Hauptargument): ").append(command.getMainParameterDescription()).append("\n\n");
}
Map<Parameterized, ParameterDescription> fields = command.getFields();
if (fields.isEmpty()) {
out.append("Dieser Befehl kann ohne Parameter verwendet werden\n\n");
}
fields.forEach(
(k, v) -> out.append("- **")
.append(k.getName())
.append("**: ")
.append(v.getDescription())
.append("\n")
);
out.append("\n#### Beispielaufruf\n\n");
out.append("```\n");
out.append("docker exec client run ").append(c);
fields.forEach(
(k, v) -> out.append(" \\\n -").append(k.getName()).append(" <value>")
);
if (name != null) {
out.append("\\\n <").append(name).append(">");
}
out.append("\n```\n\n");
out.append("\\newpage\n");
}
}
@Override
public String getCommandDescription(String s) {
return null;
}
}
docker run -v `pwd`:/data \
pandoc/latex:2.6 \
*.md \
-o result.pdf
@Parameters(commandDescription = "Import der Stammdaten (JSON files).",
commandNames = {"importStammdaten"})
public class StammdatenImportJob implements Job {
@Parameter(names = {"-encoding"}, description = "Encoding der Dateien")
private String encoding;
@Parameter(names = {"-filter"}, description = "Dateinamenfilter")
private String filter;
@Parameter(description = "Verzeichnis der zu importierenden Dateien",
arity = 1, converter = PathConverter.class)
private Path targetDir;
@Override
public void run() throws ClientException {
// Konkrete Implementierung
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.