Permalink
Browse files

Uses streamline-cli v0.3.0

  • Loading branch information...
joeha480 committed Nov 5, 2017
1 parent a4754a2 commit 082c904734dce560d14cc4fa5bdc2688bf5a1ef4
View
@@ -82,7 +82,7 @@ dependencies {
compileOnly group: "biz.aQute.bnd", name: "annotation", version: "2.3.0"
compile 'org.daisy.braille:braille-utils.api:4.1.0'
compile 'org.daisy.streamline:streamline-cli:0.2.0'
compile 'org.daisy.streamline:streamline-cli:0.3.0'
compile ('org.daisy.braille:braille-utils.pef-tools:3.0.0') {
exclude module: 'Saxon-HE'
}
@@ -89,26 +89,25 @@ public static void main(String[] args) throws InternalTaskException, IOException
for (TranslatorSpecification ts : s) {
System.out.println(" " + ts.getLocale() + ", " + ts.getMode());
}
Convert.exitWithCode(ExitCode.OK);
ExitCode.OK.exitSystem();
} else {
System.out.println("Expected at least two arguments");
System.out.println();
m.displayHelp(System.out);
Convert.exitWithCode(ExitCode.MISSING_ARGUMENT);
ExitCode.MISSING_ARGUMENT.exitSystem();
}
} else if (p.size()>2) {
System.out.println("Unknown argument(s): " + p.subList(2, p.size()));
System.out.println();
m.displayHelp(System.out);
Convert.exitWithCode(ExitCode.UNKNOWN_ARGUMENT);
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
// remove required arguments
File input = new File(p.get(0));
//File input = new File(args[0]);
if (!input.exists()) {
System.out.println("Cannot find input file: " + input);
Convert.exitWithCode(ExitCode.MISSING_RESOURCE);
ExitCode.MISSING_RESOURCE.exitSystem("Cannot find input file: " + input);
}
final File output = new File(p.get(1)).getAbsoluteFile();
@@ -134,19 +133,19 @@ public static void main(String[] args) throws InternalTaskException, IOException
logger.warning("'" + WATCH_KEY + "' is not implemented for batch mode.");
}
if ("true".equals(props.get(SystemKeys.WRITE_TEMP_FILES))) {
Convert.exitWithCode(ExitCode.ILLEGAL_ARGUMENT_VALUE, "Cannot write debug files in batch mode.");
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem("Cannot write debug files in batch mode.");
}
String format = props.get(SystemKeys.OUTPUT_FORMAT);
if (format==null) {
Convert.exitWithCode(ExitCode.MISSING_ARGUMENT, SystemKeys.OUTPUT_FORMAT + " must be specified in batch mode.");
ExitCode.MISSING_ARGUMENT.exitSystem(SystemKeys.OUTPUT_FORMAT + " must be specified in batch mode.");
} else if (format.equals(SystemKeys.PEF_FORMAT)) {
format = "pef";
} else if (format.equals(SystemKeys.TEXT_FORMAT)) {
format = "txt";
} else if (format.equals(SystemKeys.OBFL_FORMAT)) {
format = "obfl";
} else {
Convert.exitWithCode(ExitCode.ILLEGAL_ARGUMENT_VALUE, "Unknown output format.");
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem("Unknown output format.");
}
//Experimental parallelization code in comment.
//ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@@ -170,7 +169,7 @@ public static void main(String[] args) throws InternalTaskException, IOException
// e.printStackTrace();
//}
} else if (input.isDirectory()) {
Convert.exitWithCode(ExitCode.ILLEGAL_ARGUMENT_VALUE, "If input is a directory, output must be an existing directory too.");
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem("If input is a directory, output must be an existing directory too.");
} else {
String pollWaitStr = result.getOptional().get(WATCH_KEY);
if (pollWaitStr!=null) {
@@ -207,7 +206,7 @@ public static void main(String[] args) throws InternalTaskException, IOException
private void runDotify(File input, File output, String context, HashMap<String, String> props) throws InternalTaskException, IOException {
if (!input.exists()) {
Convert.exitWithCode(ExitCode.MISSING_RESOURCE, "Cannot find input file: " + input);
ExitCode.MISSING_RESOURCE.exitSystem("Cannot find input file: " + input);
}
Dotify.run(input, output, FilterLocale.parse(context), props);
int i = output.getName().lastIndexOf(".");
@@ -126,7 +126,7 @@ public void run() throws Exception {
System.out.println("Expected at least one argument.");
System.out.println();
displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
setPluginsDir(new File("plugins"));
if (HELP.equalsIgnoreCase(args[0])) {
@@ -135,11 +135,11 @@ public void run() throws Exception {
if (clazz!=null) {
AbstractUI ui = clazz.newInstance();
ui.displayHelp(System.out);
exitWithCode(ExitCode.OK);
ExitCode.OK.exitSystem();
} else {
System.out.println("Unknown argument '" + args[1] + "'");
displayHelp(System.out);
System.exit(-ExitCode.UNKNOWN_ARGUMENT.ordinal());
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
}
displayHelp(System.out);
@@ -149,7 +149,7 @@ public void run() throws Exception {
System.out.println("--- " + getName() + " ---");
System.out.println("Version: " + (getVersion()!=null?getVersion():"N/A"));
System.out.println("Build: " + (getBuildIdentifier()!=null?getBuildIdentifier():"N/A"));
DotifyCLI.exitWithCode(ExitCode.OK);
ExitCode.OK.exitSystem();
}
Class<? extends Object> clazz = commands.get(args[0]);
if (clazz!=null) {
@@ -158,7 +158,7 @@ public void run() throws Exception {
} else {
System.out.println("Unknown argument '" + args[0] + "'");
displayHelp(System.out);
System.exit(-ExitCode.UNKNOWN_ARGUMENT.ordinal());
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
}
}
@@ -220,7 +220,7 @@ public static void main(String[] args) throws BackingStoreException {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
CommandParserResult parserResult = ui.parser.parse(args);
@@ -229,13 +229,13 @@ public static void main(String[] args) throws BackingStoreException {
if ("clear".equalsIgnoreCase(p.get("settings"))) {
ui.clearSettings();
System.exit(ExitCode.OK.ordinal());
ExitCode.OK.exitSystem();
}
if ("setup".equalsIgnoreCase(p.get("settings"))) {
ui.setup();
if (firstArg==null) {
System.exit(ExitCode.OK.ordinal());
ExitCode.OK.exitSystem();
}
} else {
ui.readSetup(false);
@@ -253,8 +253,7 @@ public static void main(String[] args) throws BackingStoreException {
embossFolder.mkdir();
device = new FileDevice(embossFolder);
} else {
System.out.println(basePathStr + " does not exist or is not a directory.");
System.exit(-ExitCode.ILLEGAL_ARGUMENT_VALUE.ordinal());
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem(basePathStr + " does not exist or is not a directory.");
}
} else {
device = new PrinterDevice(ui.getDeviceName(), true);
@@ -293,8 +292,7 @@ public static void main(String[] args) throws BackingStoreException {
try {
boolean ok = new PEFValidatorFacade(ValidatorFactory.newInstance()).validate(input, System.out);
if (!ok) {
System.out.println("Validation failed, exiting...");
System.exit(-ExitCode.FAILED_TO_READ.ordinal());
ExitCode.UNEXPECTED_RESOURCE_CONTENTS.exitSystem("Validation failed, exiting...");
}
for (int i=0; i<copies; i++) {
EmbosserWriter embosserObj = ui.getEmbosser().newEmbosserWriter(device);
@@ -32,7 +32,7 @@ public static void main(String[] args) throws IOException {
CommandParserResult result = m.parser.parse(args);
if (HELP_KEY.equals(result.getOptional().get(META_KEY))) {
m.displayHelp(System.out);
EvaluateCLI.exitWithCode(ExitCode.OK);
ExitCode.OK.exitSystem();
} else {
m.runCLI(result);
}
@@ -73,7 +73,7 @@ public static void main(String[] args) throws FileNotFoundException {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
CommandParserResult pr = ui.parser.parse(args);
//Map<String, String> p =pr.toMap(ARG_PREFIX);
@@ -14,6 +14,7 @@
import org.daisy.dotify.api.writer.PagedMediaWriterFactory;
import org.daisy.dotify.consumer.engine.FormatterEngineMaker;
import org.daisy.dotify.consumer.writer.PagedMediaWriterFactoryMaker;
import org.daisy.streamline.cli.ExitCode;
public class FormatterCLI {
@@ -25,9 +26,8 @@
*/
public static void main(String[] args) throws FileNotFoundException, LayoutEngineException, PagedMediaWriterConfigurationException {
if (args.length != 4) {
System.out.println("Expected four arguments: input_file output_file locale mode");
System.out.println(" file.obfl file.pef sv-SE uncontracted");
System.exit(-1);
//System.out.println(" file.obfl file.pef sv-SE uncontracted");
ExitCode.MISSING_ARGUMENT.exitSystem("Expected four arguments: input_file output_file locale mode");
}
PagedMediaWriterFactory f = PagedMediaWriterFactoryMaker.newInstance().getFactory(MediaTypes.PEF_MEDIA_TYPE);
@@ -64,7 +64,7 @@ public static void main(String[] args) throws FileNotFoundException {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
Map<String, String> p = ui.parser.parse(args).toMap(ARG_PREFIX);
// remove required argument
@@ -66,7 +66,7 @@ public static void main(String[] args) {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
String type;
String prefix;
@@ -49,7 +49,7 @@ public static void main(String[] args) throws FileNotFoundException {
System.out.println("Expected three arguments.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
PEFFileMerger merger = new PEFFileMerger(ValidatorFactory.newInstance());
File input = new File(args[0]);
@@ -64,8 +64,7 @@ public static void main(String[] args) throws FileNotFoundException {
} else if (sortString.equalsIgnoreCase("number")) {
sort = SortType.NUMERAL_GROUPING;
} else {
System.out.println("Illegal value for argument sort: " + sortString);
System.exit(-ExitCode.ILLEGAL_ARGUMENT_VALUE.ordinal());
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem("Illegal value for argument sort: " + sortString);
}
}
merger.merge(input, new FileOutputStream(output), args[2], sort);
@@ -59,7 +59,7 @@ public static void main(String[] args) throws XPathExpressionException, ParserCo
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
Map<String, String> p = ui.parser.parse(args).toMap(ARG_PREFIX);
// remove required argument
@@ -36,6 +36,7 @@
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.Definition;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.ShortFormResolver;
@@ -100,8 +101,7 @@ public static void main(String[] args) {
// validate input
boolean ok = new PEFValidatorFacade(ValidatorFactory.newInstance()).validate(input, System.out);
if (!ok) {
System.out.println("Validation failed, exiting...");
System.exit(-1);
ExitCode.UNEXPECTED_RESOURCE_CONTENTS.exitSystem("Validation failed, exiting...");
}
// expand short forms, if any
@@ -23,6 +23,7 @@
import javax.print.PrintException;
import org.daisy.braille.utils.pef.PrinterDevice;
import org.daisy.streamline.cli.ExitCode;
/**
* Provides a command line UI for sending a file straight to a
@@ -39,8 +40,7 @@
*/
public static void main(String[] args) throws FileNotFoundException, PrintException {
if (args.length != 2) {
System.out.println("Expected two arguments: device_name path_to_file");
System.exit(-1);
ExitCode.MISSING_ARGUMENT.exitSystem("Expected two arguments: device_name path_to_file");
}
PrinterDevice bd = new PrinterDevice(args[0], true);
bd.transmit(new File(args[1]));
@@ -44,7 +44,7 @@ public static void main(String[] args) {
System.out.println("Expected two arguments.");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
File input = new File(args[0]);
File output = new File(args[1]);
@@ -63,7 +63,7 @@ public static void main(String[] args) throws IOException {
CommandParserResult result = m.parser.parse(args);
if (HELP_KEY.equals(result.getOptional().get(META_KEY))) {
m.displayHelp(System.out);
TranslateCLI.exitWithCode(ExitCode.OK);
ExitCode.OK.exitSystem();
} else {
m.runCLI(result);
}
@@ -41,12 +41,11 @@ public static void main(String[] args) throws IOException {
System.out.println("Expected one more argument: input [options ...]");
System.out.println();
ui.displayHelp(System.out);
System.exit(-ExitCode.MISSING_ARGUMENT.ordinal());
ExitCode.MISSING_ARGUMENT.exitSystem();
}
File in = new File(args[0]);
if (!in.exists()) {
System.out.println("File does not exist: " + in);
System.exit(-1);
ExitCode.MISSING_RESOURCE.exitSystem("File does not exist: " + in);
}
Mode m = Mode.values()[0];
if (args.length>1) {
@@ -63,8 +62,7 @@ public static void main(String[] args) throws IOException {
ValidatorFactory factory = ValidatorFactory.newInstance();
org.daisy.braille.utils.api.validator.Validator pv = factory.newValidator(PEFValidator.class.getCanonicalName());
if (pv == null) {
System.out.println("Could not find validator.");
System.exit(-2);
ExitCode.INTERNAL_ERROR.exitSystem("Could not find validator.");
}
pv.setFeature(PEFValidator.FEATURE_MODE, m.equals(Mode.LIGHT) ? PEFValidator.Mode.LIGHT_MODE : PEFValidator.Mode.FULL_MODE);
System.out.println("Validating " + in + " using \"" + pv.getDisplayName() + "\" (" + pv.getDescription() + ") in " + pv.getFeature(PEFValidator.FEATURE_MODE));

0 comments on commit 082c904

Please sign in to comment.