Permalink
Browse files

Uses streamline-cli v0.4.0

  • Loading branch information...
joeha480 committed Nov 5, 2017
1 parent f14db97 commit 4ee977ff6a23777728c17386343e893a43572f71
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.2.0'
compile 'org.daisy.streamline:streamline-cli:0.3.0'
compile 'org.daisy.streamline:streamline-cli:0.4.0'
compile ('org.daisy.braille:braille-utils.pef-tools:3.0.0') {
exclude module: 'Saxon-HE'
}
@@ -32,20 +32,22 @@
import org.daisy.dotify.consumer.tasks.TaskGroupFactoryMaker;
import org.daisy.dotify.consumer.translator.BrailleTranslatorFactoryMaker;
import org.daisy.dotify.tasks.runner.DefaultTempFileWriter;
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.CommandDetails;
import org.daisy.streamline.cli.CommandParser;
import org.daisy.streamline.cli.CommandParserResult;
import org.daisy.streamline.cli.Definition;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.SwitchArgument;
import org.daisy.streamline.cli.SwitchMap;
import org.xml.sax.SAXException;
/**
* Provides a command line entry point to Dotify.
* @author Joel Håkansson
*/
public class Convert extends AbstractUI {
public class Convert implements CommandDetails {
private static final Logger logger = Logger.getLogger(Convert.class.getCanonicalName());
//private static final String DEFAULT_TEMPLATE = "A4-w32";
private static final String DEFAULT_LOCALE = Locale.getDefault().toString().replaceAll("_", "-");
@@ -58,16 +60,21 @@
private final List<Argument> reqArgs;
private final List<OptionalArgument> optionalArgs;
private final SwitchMap switches;
private final BrailleUtilsInfo brailleInfo;
private final CommandParser parser;
public Convert() {
this.brailleInfo = new BrailleUtilsInfo();
//Use lazy loading of argument details
this.reqArgs = new ArrayList<Argument>();
this.optionalArgs = new ArrayList<OptionalArgument>();
parser.addSwitch(new SwitchArgument('w', WATCH_KEY, WATCH_KEY, "" + DEFAULT_POLL_TIME, "Keeps the conversion in sync by watching the input file for changes and rerunning the conversion automatically when the input is modified."));
parser.addSwitch(new SwitchArgument('o', SystemKeys.LIST_OPTIONS, SystemKeys.LIST_OPTIONS, "true", "Lists additional options as the conversion runs."));
parser.addSwitch(new SwitchArgument('c', CONFIG_KEY, META_KEY, CONFIG_KEY, "Lists known configurations."));
this.switches = new SwitchMap.Builder()
.addSwitch(new SwitchArgument('w', WATCH_KEY, WATCH_KEY, "" + DEFAULT_POLL_TIME, "Keeps the conversion in sync by watching the input file for changes and rerunning the conversion automatically when the input is modified."))
.addSwitch(new SwitchArgument('o', SystemKeys.LIST_OPTIONS, SystemKeys.LIST_OPTIONS, "true", "Lists additional options as the conversion runs."))
.addSwitch(new SwitchArgument('c', CONFIG_KEY, META_KEY, CONFIG_KEY, "Lists known configurations."))
.build();
this.parser = CommandParser.create(this);
}
/**
@@ -94,13 +101,13 @@ public static void main(String[] args) throws InternalTaskException, IOException
System.out.println("Expected at least two arguments");
System.out.println();
m.displayHelp(System.out);
m.parser.displayHelp(System.out);
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);
m.parser.displayHelp(System.out);
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
// remove required arguments
@@ -225,7 +232,11 @@ private void runDotify(File input, File output, String context, HashMap<String,
// create brl
HashMap<String, String> p = new HashMap<String, String>();
p.put(PEFConverterFacade.KEY_TABLE, props.get(PEFConverterFacade.KEY_TABLE));
expandShortForm(p, PEFConverterFacade.KEY_TABLE, brailleInfo.getShortFormResolver());
try {
brailleInfo.getShortFormResolver().expandShortForm(p, PEFConverterFacade.KEY_TABLE);
} catch (IllegalArgumentException e) {
ExitCode.ILLEGAL_ARGUMENT_VALUE.exitSystem(e.getMessage());
}
File f = new File(output.getParentFile(), output.getName() + ".brl");
logger.info("Writing brl to " + f.getAbsolutePath());
try (FileOutputStream os = new FileOutputStream(f)) {
@@ -310,4 +321,9 @@ public String getDescription() {
return optionalArgs;
}
@Override
public SwitchMap getSwitches() {
return switches;
}
}
@@ -12,20 +12,22 @@
import org.daisy.braille.utils.pef.FileTools;
import org.daisy.dotify.SystemProperties;
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.CommandDetails;
import org.daisy.streamline.cli.CommandParser;
import org.daisy.streamline.cli.CommandParserResult;
import org.daisy.streamline.cli.Definition;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.SwitchArgument;
import org.daisy.streamline.cli.SwitchMap;
/**
* Provides a basic command line UI for core functionality in
* org.daisy.braille.
* @author Joel Håkansson
*/
public class DotifyCLI extends AbstractUI {
public class DotifyCLI implements CommandDetails {
public static final String EMBOSS = "emboss";
public static final String TEXT2PEF = "text2pef";
public static final String PEF2TEXT = "pef2text";
@@ -48,8 +50,10 @@
private final String[] args;
private final Logger logger;
private final Map<String, Class<? extends AbstractUI>> commands;
private final Map<String, Class<? extends CommandDetails>> commands;
private final SwitchMap switches;
private final List<Definition> values;
private final CommandParser parser;
/**
* Creates a new Basic UI
@@ -80,8 +84,11 @@ public DotifyCLI(String[] args) {
//Diagnostics commands
putCommand(GENERATE, "generates a random PEF-file for testing", GeneratePEF.class);
this.switches = new SwitchMap.Builder()
.addSwitch(new SwitchArgument('v', VERSION_KEY, META_KEY, VERSION_KEY, "Displays version information."))
.build();
putCommand(LIST, "lists stuff", ListStuff.class);
parser.addSwitch(new SwitchArgument('v', VERSION_KEY, META_KEY, VERSION_KEY, "Displays version information."));
this.parser = CommandParser.create(this);
//Help
values.add(new Definition(HELP, "Without additional arguments, this text is displayed. To get help on a specific command, type help <command>"));
@@ -95,7 +102,7 @@ public DotifyCLI(String[] args) {
}*/
}
protected void putCommand(String cmd, String desc, Class<? extends AbstractUI> c) {
protected void putCommand(String cmd, String desc, Class<? extends CommandDetails> c) {
values.add(new Definition(cmd, desc));
commands.put(cmd, c);
}
@@ -125,24 +132,26 @@ public void run() throws Exception {
if (args.length<1) {
System.out.println("Expected at least one argument.");
System.out.println();
displayHelp(System.out);
parser.displayHelp(System.out);
ExitCode.MISSING_ARGUMENT.exitSystem();
}
setPluginsDir(new File("plugins"));
if (HELP.equalsIgnoreCase(args[0])) {
if (args.length>=2) {
Class<? extends AbstractUI> clazz = commands.get(args[1]);
Class<? extends CommandDetails> clazz = commands.get(args[1]);
if (clazz!=null) {
AbstractUI ui = clazz.newInstance();
ui.displayHelp(System.out);
CommandDetails ui = clazz.newInstance();
new CommandParser.Builder(ui)
.build()
.displayHelp(System.out);
ExitCode.OK.exitSystem();
} else {
System.out.println("Unknown argument '" + args[1] + "'");
displayHelp(System.out);
parser.displayHelp(System.out);
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
}
displayHelp(System.out);
parser.displayHelp(System.out);
} else {
CommandParserResult result = parser.parse(args);
if (result.getRequired().isEmpty() && VERSION_KEY.equals(result.getOptional().get(META_KEY))) {
@@ -157,7 +166,7 @@ public void run() throws Exception {
method.invoke(null, (Object)getArgsSubList(1));
} else {
System.out.println("Unknown argument '" + args[0] + "'");
displayHelp(System.out);
parser.displayHelp(System.out);
ExitCode.UNKNOWN_ARGUMENT.exitSystem();
}
}
@@ -216,4 +225,9 @@ public String getVersion() {
public String getBuildIdentifier() {
return SystemProperties.SYSTEM_BUILD;
}
@Override
public SwitchMap getSwitches() {
return switches;
}
}
@@ -59,20 +59,26 @@
import org.daisy.braille.utils.pef.PrinterDevice;
import org.daisy.braille.utils.pef.Range;
import org.daisy.braille.utils.pef.UnsupportedWidthException;
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.CommandDetails;
import org.daisy.streamline.cli.CommandParser;
import org.daisy.streamline.cli.CommandParserResult;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.SwitchArgument;
import org.daisy.streamline.cli.SwitchMap;
import org.xml.sax.SAXException;
/**
* Provides a UI for embossing a PEF-file.
* Not for public use. This class is a package class. Use DotifyCLI
* @author Joel Håkansson
*/
class EmbossPEF extends AbstractUI {
class EmbossPEF implements CommandDetails {
/**
* Prefix used for required arguments in the arguments map
*/
public static final String ARG_PREFIX = "required-";
public static final String DEVICE_NAME = "device name";
public static final String EMBOSSER_TYPE = "embosser type";
public static final String TABLE_TYPE = "table type";
@@ -86,6 +92,8 @@
private final List<Argument> reqArgs;
private final List<OptionalArgument> optionalArgs;
private final SwitchMap switches;
private final CommandParser parser;
private String deviceName;
private Embosser type;
@@ -105,8 +113,11 @@ public EmbossPEF() {
optionalArgs.add(new OptionalArgument(KEY_RANGE, "Emboss a range of pages", "1-"));
optionalArgs.add(new OptionalArgument(KEY_COPIES, "Set copies", "1"));
optionalArgs.add(new OptionalArgument(KEY_DIR, "Send the embosser data to a folder instead of the specified device.", ""));
parser.addSwitch(new SwitchArgument("clear", "settings", "clear", "To clear settings"));
parser.addSwitch(new SwitchArgument("setup", "settings", "setup", "To change setup"));
this.switches = new SwitchMap.Builder()
.addSwitch(new SwitchArgument("clear", "settings", "clear", "To clear settings"))
.addSwitch(new SwitchArgument("setup", "settings", "setup", "To change setup"))
.build();
this.parser = CommandParser.create(this);
}
protected void readSetup(boolean verify) {
@@ -219,7 +230,7 @@ public static void main(String[] args) throws BackingStoreException {
if (args.length<1) {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
ui.parser.displayHelp(System.out);
ExitCode.MISSING_ARGUMENT.exitSystem();
}
@@ -373,4 +384,9 @@ public String getDescription() {
return optionalArgs;
}
@Override
public SwitchMap getSwitches() {
return switches;
}
}
@@ -8,30 +8,37 @@
import org.daisy.dotify.api.obfl.Expression;
import org.daisy.dotify.consumer.obfl.ExpressionFactoryMaker;
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.CommandDetails;
import org.daisy.streamline.cli.CommandParser;
import org.daisy.streamline.cli.CommandParserResult;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.SwitchArgument;
import org.daisy.streamline.cli.SwitchMap;
public class EvaluateCLI extends AbstractUI {
public class EvaluateCLI implements CommandDetails {
private final static String META_KEY = "meta";
private final static String HELP_KEY = "help";
private final List<Argument> reqArgs;
private final List<OptionalArgument> optionalArgs;
private final SwitchMap switches;
private final CommandParser parser;
public EvaluateCLI() {
this.reqArgs = new ArrayList<Argument>();
this.optionalArgs = new ArrayList<OptionalArgument>();
parser.addSwitch(new SwitchArgument('h', HELP_KEY, META_KEY, HELP_KEY, "Help text."));
this.switches = new SwitchMap.Builder()
.addSwitch(new SwitchArgument('h', HELP_KEY, META_KEY, HELP_KEY, "Help text."))
.build();
this.parser = CommandParser.create(this);
}
public static void main(String[] args) throws IOException {
EvaluateCLI m = new EvaluateCLI();
CommandParserResult result = m.parser.parse(args);
if (HELP_KEY.equals(result.getOptional().get(META_KEY))) {
m.displayHelp(System.out);
m.parser.displayHelp(System.out);
ExitCode.OK.exitSystem();
} else {
m.runCLI(result);
@@ -77,4 +84,9 @@ public String getName() {
return reqArgs;
}
@Override
public SwitchMap getSwitches() {
return switches;
}
}
@@ -38,22 +38,26 @@
import org.daisy.dotify.cli.pefinfo.DetailSet;
import org.daisy.dotify.cli.pefinfo.PEFBookInfo;
import org.daisy.dotify.cli.pefinfo.URIDetail;
import org.daisy.streamline.cli.AbstractUI;
import org.daisy.streamline.cli.Argument;
import org.daisy.streamline.cli.CommandDetails;
import org.daisy.streamline.cli.CommandParser;
import org.daisy.streamline.cli.CommandParserResult;
import org.daisy.streamline.cli.ExitCode;
import org.daisy.streamline.cli.OptionalArgument;
import org.daisy.streamline.cli.SwitchArgument;
import org.daisy.streamline.cli.SwitchMap;
import org.xml.sax.SAXException;
/**
* Provides a UI for finding PEF-files. Not for public use.
* This class is a package class. Use DotifyCLI
* @author Joel Håkansson
*/
class FindPEF extends AbstractUI {
class FindPEF implements CommandDetails {
private final List<Argument> reqArgs;
private final List<OptionalArgument> optionalArgs;
private final SwitchMap switches;
private final CommandParser parser;
private static final String FOLDER_KEY = "folder";
private static final String RECURSIVE_KEY = "recursive";
@@ -63,16 +67,19 @@ public FindPEF() {
reqArgs = new ArrayList<Argument>();
optionalArgs = new ArrayList<OptionalArgument>();
optionalArgs.add(new OptionalArgument(FOLDER_KEY, "Folder path", (new File("")).getAbsolutePath()));
parser.addSwitch(new SwitchArgument('r', RECURSIVE_KEY, "true", "Include subfolders in the scan."));
parser.addSwitch(new SwitchArgument('i', INTERACTIVE_KEY, "true", "Starts an interactive shell for repeated queries."));
this.switches = new SwitchMap.Builder()
.addSwitch(new SwitchArgument('r', RECURSIVE_KEY, "true", "Include subfolders in the scan."))
.addSwitch(new SwitchArgument('i', INTERACTIVE_KEY, "true", "Starts an interactive shell for repeated queries."))
.build();
this.parser = CommandParser.create(this);
}
public static void main(String[] args) throws FileNotFoundException {
FindPEF ui = new FindPEF();
if (args.length<1) {
System.out.println("Expected at least one more argument.");
System.out.println();
ui.displayHelp(System.out);
ui.parser.displayHelp(System.out);
ExitCode.MISSING_ARGUMENT.exitSystem();
}
CommandParserResult pr = ui.parser.parse(args);
@@ -146,4 +153,9 @@ public String getDescription() {
return "Finds PEF-files.";
}
@Override
public SwitchMap getSwitches() {
return switches;
}
}
Oops, something went wrong.

0 comments on commit 4ee977f

Please sign in to comment.