Skip to content

Commit

Permalink
Now all actions are invoked using --action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed May 24, 2020
1 parent ff7b51c commit 5d2cdf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 41 deletions.
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- factory for xrechnung
- new sample innvoice
- complete or discard read into push provider
- validate as library doc
- javadoc export

done
- 2.1 now default
Expand All @@ -15,6 +17,7 @@ done
- integrates mustangserver
- modular project setup
- getSellerTradePartyAddress (PR #157 ) thanks to aberndt-hub
- switched from eclipse to IntelliJ


1.7.7
Expand Down
74 changes: 34 additions & 40 deletions Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ private static void printUsage() {
}

private static String getUsage() {
return "Usage: [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n"
+ "* Count operations\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n"
return "Usage: --action metrics|combine|extract|a3only|upgrade|validate [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n"
+ "* merics\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n"
+ " If it is a directory, it will recurse.\n"
+ " -l, --listfromstdin count ZUGFeRD files from a list of linefeed separated files on runtime.\n"
+ " It will start once a blank line has been entered.\n" + "\n"
+ " Additional parameter for both count operations\n"
+ " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf)\n"
+ "\n" + "* Merge operations\n" + " -e, --extract extract ZUGFeRD PDF to XML file\n"
+ "\n" + "* Merge actions\n" + " extract extract ZUGFeRD PDF to XML file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output XML file\n"
+ " -u, --upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
+ " upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input XML ZUGFeRD 1 file\n"
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
+ " -a, --a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
+ " a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " -c, --combine combine XML and PDF file to ZUGFeRD PDF file\n"
+ " combine combine XML and PDF file to ZUGFeRD PDF file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--source-xml <filename>]: set input XML file\n"
Expand All @@ -80,7 +80,11 @@ private static String getUsage() {
+ " [--version <1|2>]: set ZUGFeRD version\n"
+ " [--profile <...>]: set ZUGFeRD profile\n"
+ " For ZUGFeRD v1: <B>ASIC, <C>OMFORT or <E>XTENDED\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, E<X>TENDED ";
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, E<X>TENDED "
+ " validate validate XML or PDF file \n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: input PDF or XML file\n"
;
}

private static void printHelp() {
Expand Down Expand Up @@ -254,23 +258,6 @@ public static void main(String[] args) {
// --out: output file
Option<String> outOption = parser.addStringOption("out");

// Command: Extract XML
// --extract
// (--source: input PDF file)
// (--out: output XML file)
Option<Boolean> extractOption = parser.addBooleanOption('e', "extract");

// Command: Migrating ZUGFeRD 1 to 2
// --upgrade
// (--source: input XML ZUGFeRD 1 file)
// (--out: output XML ZUGFeRD 2 file)
Option<Boolean> upgradeOption = parser.addBooleanOption('u', "upgrade");

// Command: Convert PDF/A-1 to PDF/A-3
// --a3only
// (--source: input PDF file)
// (--out: output PDF file)
Option<Boolean> a3onlyOption = parser.addBooleanOption('a', "a3only");

// Command: Combining PDF and XML
// --combine
Expand All @@ -279,7 +266,6 @@ public static void main(String[] args) {
// (--out: output PDF file)
// (--version: ZUGFeRD version)
// (--profile: ZUGFeRD profile)
Option<Boolean> combineOption = parser.addBooleanOption('c', "combine");
Option<String> sourceXmlOption = parser.addStringOption("source-xml");
Option<String> formatOption = parser.addStringOption('f', "format");
Option<String> zugferdVersionOption = parser.addStringOption("version");
Expand Down Expand Up @@ -307,12 +293,8 @@ public static void main(String[] args) {
String action = parser.getOptionValue(actionOption);
String directoryName = parser.getOptionValue(dirnameOption);
Boolean filesFromStdIn = parser.getOptionValue(filesFromStdInOption, Boolean.FALSE);
Boolean combineRequested = parser.getOptionValue(combineOption, Boolean.FALSE) || ((action!=null)&&(action.equals("combine")));
Boolean extractRequested = parser.getOptionValue(extractOption, Boolean.FALSE) || ((action!=null)&&(action.equals("extract")));
Boolean helpRequested = parser.getOptionValue(helpOption, Boolean.FALSE) || ((action!=null)&&(action.equals("help")));
Boolean upgradeRequested = parser.getOptionValue(upgradeOption, Boolean.FALSE) || ((action!=null)&&(action.equals("upgrade")));
Boolean ignoreFileExt = parser.getOptionValue(ignoreFileExtOption, Boolean.FALSE);
Boolean a3only = parser.getOptionValue(a3onlyOption, Boolean.FALSE) || ((action!=null)&&(action.equals("a3")));
String sourceName = parser.getOptionValue(sourceOption);
String sourceXMLName = parser.getOptionValue(sourceXmlOption);
String outName = parser.getOptionValue(outOption);
Expand All @@ -323,29 +305,24 @@ public static void main(String[] args) {
if (helpRequested) {
printHelp();
optionsRecognized=true;
} else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) {
} else if ((action!=null)&&(action.equals("metrics"))) {
performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
optionsRecognized=true;
} else if (combineRequested) {
} else if ((action!=null)&&(action.equals("combine"))) {
performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile);
optionsRecognized=true;
} else if (extractRequested) {
} else if ((action!=null)&&(action.equals("extract"))) {
performExtract(sourceName, outName);
optionsRecognized=true;
} else if (a3only) {
} else if ((action!=null)&&(action.equals("a3only"))) {
performConvert(sourceName, outName);
optionsRecognized=true;
} else if (upgradeRequested) {
} else if ((action!=null)&&(action.equals("upgrade"))) {
performUpgrade(sourceName, outName);
optionsRecognized=true;
} else if ((action!=null)&&(action.equals("validate"))) {
ZUGFeRDValidator zfv=new ZUGFeRDValidator();
System.out.println(zfv.validate(sourceName));

optionsRecognized = !zfv.hasOptionsError();
if (!zfv.wasCompletelyValid()) {
System.exit(-1);
}
optionsRecognized=performValidate(sourceName);

} else {
// no argument or argument unknown
Expand All @@ -360,6 +337,23 @@ public static void main(String[] args) {

}

private static boolean performValidate(String sourceName) {
boolean optionsRecognized;
if (sourceName == null) {
sourceName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
} else {
System.out.println("Source PDF set to " + sourceName);
}

ZUGFeRDValidator zfv=new ZUGFeRDValidator();
System.out.println(zfv.validate(sourceName));
optionsRecognized = !zfv.hasOptionsError();
if (!zfv.wasCompletelyValid()) {
System.exit(-1);
}
return optionsRecognized;
}

private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {

// Get params from user if not already defined
Expand Down
2 changes: 1 addition & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>library</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Library for to write and read FacturX 1.0 and ZUGFeRD 1.0 and 2.1 e-invoices. A PDF/A file is required, the XML can be generated or provided. </name>
<name>Library to write and read FacturX 1.0 and ZUGFeRD 1.0 and 2.1 e-invoices. A PDF/A file is required, the XML can be generated or provided. </name>
<description>The Mustang project is a java library to read and write ZUGFeRD meta data inside your invoice PDFs
</description>
<url>http://www.mustangproject.org/</url>
Expand Down

0 comments on commit 5d2cdf2

Please sign in to comment.