added powershell compat

This commit is contained in:
jstaerk
2024-06-30 19:18:42 +02:00
parent 53391eaf13
commit c0dd17eba9
2 changed files with 23 additions and 10 deletions

View File

@@ -8,6 +8,8 @@
- #397 - #397
- #392 CLI: action combine: --ignorefileextension to ignore PDF/A input file errors dosen't work - #392 CLI: action combine: --ignorefileextension to ignore PDF/A input file errors dosen't work
- for CLI combine, fx is now default - for CLI combine, fx is now default
- set profile to XR if XR is imported #395
- Powershell compatibility: added --no-additional-attachments command line option for better batch processing
2.11.0 2.11.0
======= =======

View File

@@ -71,6 +71,7 @@ public class Main {
+ " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n" + " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n" + " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
+ " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n" + " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n"
+ " [--no-additional-attachments]: prevent prompting for attachments\n"
+ " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n" + " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n"
+ " [--source <filename>]: set input XML file\n" + " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output XML file\n" + " [--out <filename>]: set output XML file\n"
@@ -340,6 +341,7 @@ public class Main {
options.addOption(new Option("f", "format", true, "which format to output")); options.addOption(new Option("f", "format", true, "which format to output"));
options.addOption(new Option("version", "version", true, "which version of the standard to use")); options.addOption(new Option("version", "version", true, "which version of the standard to use"));
options.addOption(new Option("profile", "profile", true, "which profile of the standard to use")); options.addOption(new Option("profile", "profile", true, "which profile of the standard to use"));
options.addOption(new Option("no-additional-attachments", "no-additional-attachments", false, "prevent prompting for attachments"));
Option attachmentOpt = new Option("attachments", "attachments", true, "File attachments"); Option attachmentOpt = new Option("attachments", "attachments", true, "File attachments");
attachmentOpt.setValueSeparator(','); attachmentOpt.setValueSeparator(',');
attachmentOpt.setArgs(Option.UNLIMITED_VALUES); attachmentOpt.setArgs(Option.UNLIMITED_VALUES);
@@ -368,6 +370,7 @@ public class Main {
String directoryName = cmd.getOptionValue("directory"); String directoryName = cmd.getOptionValue("directory");
Boolean filesFromStdIn = cmd.hasOption("listfromstdin");//((Number)cmdLine.getParsedOptionValue("integer-option")).intValue(); Boolean filesFromStdIn = cmd.hasOption("listfromstdin");//((Number)cmdLine.getParsedOptionValue("integer-option")).intValue();
Boolean ignoreFileExt = cmd.hasOption("ignorefileextension"); Boolean ignoreFileExt = cmd.hasOption("ignorefileextension");
Boolean noAttachments = cmd.hasOption("no-additional-attachments");
Boolean helpRequested = cmd.hasOption("help") || ((action != null) && (action.equals("help"))); Boolean helpRequested = cmd.hasOption("help") || ((action != null) && (action.equals("help")));
disableFileLogging = cmd.hasOption("disable-file-logging"); disableFileLogging = cmd.hasOption("disable-file-logging");
@@ -403,7 +406,7 @@ public class Main {
performMetrics(directoryName, filesFromStdIn, ignoreFileExt); performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
optionsRecognized = true; optionsRecognized = true;
} else if ((action != null) && (action.equals("combine"))) { } else if ((action != null) && (action.equals("combine"))) {
performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, ignoreFileExt, attachmentFilenames, attachments); performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, ignoreFileExt, attachmentFilenames, attachments, noAttachments);
optionsRecognized = true; optionsRecognized = true;
} else if ((action != null) && (action.equals("extract"))) { } else if ((action != null) && (action.equals("extract"))) {
performExtract(sourceName, outName); performExtract(sourceName, outName);
@@ -441,7 +444,11 @@ public class Main {
System.exit(2); System.exit(2);
} }
} catch (Exception e) { } catch (Exception e) {
if (LOGGER != null) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
} else {
System.err.println(e.getMessage());
}
System.exit(-1); System.exit(-1);
} }
@@ -548,7 +555,7 @@ public class Main {
} }
private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion, private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion,
String zfProfile, Boolean ignoreInputErrors, String[] attachmentFilenames, ArrayList<FileAttachment> attachments) throws Exception { String zfProfile, Boolean ignoreInputErrors, String[] attachmentFilenames, ArrayList<FileAttachment> attachments, Boolean noAttachments) throws Exception {
/* /*
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory() * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
* .setProducer("toecount") .setCreator(System.getProperty("user.name")) * .setProducer("toecount") .setCreator(System.getProperty("user.name"))
@@ -579,12 +586,14 @@ public class Main {
if (attachmentFilenames == null) { if (attachmentFilenames == null) {
byte attachmentContents[] = null; byte attachmentContents[] = null;
String attachmentFilename, attachmentMime, attachmentDescription; String attachmentFilename, attachmentMime, attachmentDescription;
if (!noAttachments) {
attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false); attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false);
if (attachmentFilename.length() != 0) { if (attachmentFilename.length() != 0) {
attachmentContents = Files.readAllBytes(Paths.get(attachmentFilename)); attachmentContents = Files.readAllBytes(Paths.get(attachmentFilename));
attachmentMime = Files.probeContentType(Paths.get(attachmentFilename)); attachmentMime = Files.probeContentType(Paths.get(attachmentFilename));
attachments.add(new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents)); attachments.add(new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents));
} }
}
} else { } else {
for (int i = 0; i < attachmentFilenames.length; i++) { for (int i = 0; i < attachmentFilenames.length; i++) {
String attachmentFilename = attachmentFilenames[i]; String attachmentFilename = attachmentFilenames[i];
@@ -731,7 +740,9 @@ public class Main {
System.out.println("Written to " + outName); System.out.println("Written to " + outName);
} catch (Exception e) { } catch (Exception e) {
if (LOGGER != null) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
}
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }
} }