/*
* Copyright (c) 2012. Plain Source S.P.R.L.
*
* This file is part of UBL4J.
*
* UBL4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UBL4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with UBL4J. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openinvoice.ubl4j.ui;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.openinvoice.ubl4j.ui.console.UBL4JConsole;
import org.openinvoice.ubl4j.ui.console.UBL4JConsoleOptions;
import org.openinvoice.ubl4j.util.UBL4JConfigurationBeanBuilder;
import org.openinvoice.ubl4j.util.Version;
public class Main {
private static UBL4JConsoleOptions options = new UBL4JConsoleOptions();
private static CmdLineParser parser = new CmdLineParser(options);
/**
* Processes the commandline options.
*
* @param args commandline options
*/
public static void main(String[] args) {
if (args.length == 0) {
printUsageAndExit();
}
UBL4JConsole console = new UBL4JConsole();
try {
parser.parseArgument(args);
console.setOptions(options);
console.start();
if (options.convertOrderToInvoice != null) {
console.executeCreateInvoiceBasedOnOrderTask();
} else if (options.renderInvoice != null && !options.renderInvoice.isEmpty()) {
console.executeInvoiceRenderingTask();
} else if (options.help) {
printUsageAndExit();
} else if (options.config) {
printDefaultConfigurationInformation();
} else {
printUsageAndExit();
}
console.end();
} catch (CmdLineException e) {
printUsageAndExit();
} catch (Exception e) {
console.logExceptionAndExit(options, e);
}
}
public static void printDefaultConfigurationInformation() {
System.out.println(UBL4JConfigurationBeanBuilder.getInstance().toString());
}
public static void printUsageAndExit() {
System.out.println(Version.format());
parser.printUsage(System.out);
System.exit(0);
}
}