List of usage examples for org.apache.commons.cli MissingArgumentException MissingArgumentException
public MissingArgumentException(Option option)
MissingArgumentException
with the specified detail message. From source file:org.dcm4che3.tool.qc.QC.java
private static Code toCode(String codeComponents) throws MissingArgumentException { String[] components = codeComponents.split(":"); if (components.length < 3) throw new MissingArgumentException("Invalid code specified " + " code can be specified as codevalue" + ":codeschemedesignator" + ":codemeaning:codeversion where only " + "version is optional"); return new Code(components[0], components[2], components.length == 4 ? components[3] : null, components[1]); }
From source file:org.dcm4che3.tool.qc.QC.java
private static void initializeOptions(CommandLine cl, QC qc) throws MissingArgumentException { if (qc.operation == QCOperation.UPDATE) if (!cl.hasOption("update-scope")) throw new MissingArgumentException( "Missing required argument" + " update scope for update operation"); else/*from ww w. ja v a2 s . c om*/ qc.setUpdateScope(QCUpdateScope.valueOf(cl.getOptionValue("update-scope"))); if (cl.hasOption("overridestudyattributes")) qc.targetStudyAttrs = getAttributes(cl, "overridestudyattributes"); if (cl.hasOption("overrideseriesattributes")) qc.setTargetSeriesAttrs(getAttributes(cl, "overrideseriesattributes")); if (cl.hasOption("updateattributes")) qc.setUpdateAttrs(getAttributes(cl, "updateattributes")); if (cl.hasOption("targetpatientattributes")) qc.setTargetPatientAttributes(getAttributes(cl, "targetpatientattributes")); if (cl.hasOption("sourcepatientattributes")) qc.setSourcePatientAttributes(getAttributes(cl, "sourcepatientattributes")); if (cl.hasOption("pid")) qc.setPid(toIDWithIssuer(cl.getOptionValue("pid"))); if (cl.hasOption("moveuids")) qc.setMoveUIDs(toUIDS(cl.getOptionValue("moveuids"))); if (cl.hasOption("cloneuids")) qc.setCloneUIDs(toUIDS(cl.getOptionValue("cloneuids"))); if (cl.hasOption("restorerejectuids")) qc.setRrUIDs(toUIDS(cl.getOptionValue("restorerejectuids"))); if (cl.hasOption("mergestudyuids")) qc.setMergeUIDs(toUIDS(cl.getOptionValue("mergeuids"))); if (cl.hasOption("deleteobject") && qc.getOperation() == QCOperation.DELETE) qc.setDeleteParams(cl.getOptionValue("deleteobject")); }
From source file:org.dcm4che3.tool.stowrs.StowRS.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = null;// w w w. j ava2 s . c o m try { cl = parseComandLine(args); StowRS instance = new StowRS(); if (cl.hasOption("m")) instance.keys = configureKeys(instance, cl); if (!cl.hasOption("u")) { throw new IllegalArgumentException("Missing url"); } else { instance.URL = cl.getOptionValue("u"); } if (cl.hasOption("t")) { if (!cl.hasOption("ts")) { throw new MissingArgumentException("Missing option required option ts when sending metadata"); } else { instance.setTransferSyntax(cl.getOptionValue("ts")); } String mediaTypeString = cl.getOptionValue("t"); if ("JSON".equalsIgnoreCase(mediaTypeString)) { instance.mediaType = StowMetaDataType.JSON; } else if ("XML".equalsIgnoreCase(mediaTypeString)) { instance.mediaType = StowMetaDataType.XML; } else { throw new IllegalArgumentException( "Bad Type " + mediaTypeString + " specified for metadata, specify either XML or JSON"); } } else { instance.mediaType = StowMetaDataType.NO_METADATA_DICOM; } for (Iterator<String> iter = cl.getArgList().iterator(); iter.hasNext();) { instance.files.add(new File(iter.next())); } if (instance.files.isEmpty()) throw new IllegalArgumentException("Missing files"); instance.stow(); } catch (Exception e) { if (!cl.hasOption("u")) { LOG.error("stowrs: missing required option -u"); LOG.error("Try 'stowrs --help' for more information."); System.exit(2); } else { LOG.error("Error: \n", e); e.printStackTrace(); } } }
From source file:scoutdoc.main.Main.java
/** * @param args//from w w w. ja va2 s . c o m */ public static void main(String[] args) { Option optHelp = new Option(HELP_ID, "help", false, "print this message"); Option optProp = new Option(PROP_ID, "config", true, "configuration file"); optProp.setArgName("file"); //source Option optTask = new Option(SOURCE_TASKS_ID, "task", true, "(source) one or many task files"); optTask.setArgName("files"); optTask.setArgs(Option.UNLIMITED_VALUES); Option optAllPages = new Option(SOURCE_ALL_PAGES_ID, "pages", false, "(source) use the pages contained in the source folder"); Option optListPages = new Option(SOURCE_LIST_ID, "list", true, "(source) list of pages contained in the file"); optListPages.setArgName("file"); Option optRecentChange = new Option(SOURCE_RECENT_CHANGES_ID, "recent-changes", false, "(source) use the pages from the wiki recent changes"); Option optRss = new Option(SOURCE_RSS_ID, "rss", false, "(source) use the pages from the rss feed of the wiki"); OptionGroup sourceGroup = new OptionGroup(); sourceGroup.setRequired(true); sourceGroup.addOption(optTask); sourceGroup.addOption(optAllPages); sourceGroup.addOption(optListPages); sourceGroup.addOption(optRecentChange); sourceGroup.addOption(optRss); Option optfilter = new Option(SOURCE_FILTER_ID, "filter", true, "Filter for list of pages used as source"); optfilter.setArgName("class"); List<String> values = Lists.newArrayList(); for (Operation o : Operation.values()) { values.add(o.name()); } Option optOperation = new Option(OPERATION_ID, "operation", true, "operation: " + Joiner.on(", ").join(values)); optOperation.setArgName("operations"); optOperation.setArgs(Option.UNLIMITED_VALUES); optOperation.setRequired(true); Option optOutputCheckstyle = new Option(OUTPUT_CHECKSTYLE_ID, "output-checkstyle", true, "(CHECK output) create a xml checkstyle file (<filename> is optional. Default: " + DEFAULT_CHECKSTYLE_NAME + ")"); optOutputCheckstyle.setArgName("filename"); optOutputCheckstyle.setOptionalArg(true); Option optOutputDashboard = new Option(OUTPUT_DASHBOARD_ID, "output-dashboard", true, "(CHECK output) create an html dashboard (<folder> is optional. Default: " + DEFAULT_DASHBOARD_NAME + ")"); optOutputDashboard.setArgName("folder"); optOutputDashboard.setOptionalArg(true); Options options = new Options(); options.addOption(optHelp); options.addOption(optProp); options.addOptionGroup(sourceGroup); options.addOption(optfilter); options.addOption(optOperation); options.addOption(optOutputCheckstyle); options.addOption(optOutputDashboard); try { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(HELP_ID)) { printHelpAndExit(options); } if (cmd.hasOption(PROP_ID)) { ProjectProperties.initProperties(cmd.getOptionValue(PROP_ID)); } Pages.initPageList(); List<Operation> operations = readOptionEnum(cmd, optOperation, Operation.class); List<Task> tasks = readTasks(cmd, optTask); Collection<Page> pageList; if (cmd.hasOption(SOURCE_ALL_PAGES_ID)) { pageList = PageUtility.loadPages(ProjectProperties.getFolderWikiSource()); } else if (cmd.hasOption(SOURCE_LIST_ID)) { String name = cmd.getOptionValue(SOURCE_LIST_ID); try { pageList = PageUtility.readList(name); } catch (IOException e) { throw new MissingArgumentException("IOException for file <" + name + "> for <" + optListPages.getLongOpt() + "> : " + e.getMessage()); } } else { pageList = Collections.emptyList(); } IPageFilter filter; if (cmd.hasOption(SOURCE_FILTER_ID)) { if (tasks.size() > 0) { throw new MissingArgumentException("Filter <" + optfilter.getLongOpt() + "> is not allowed for source <" + optTask.getLongOpt() + ">."); } filter = newInstance(cmd.getOptionValue(SOURCE_FILTER_ID), IPageFilter.class, new AcceptAllPageFilter()); } else { filter = new AcceptAllPageFilter(); } List<Page> pages = Lists.newArrayList(); for (Page page : pageList) { if (filter.keepPage(page)) { pages.add(page); } } if (operations.contains(Operation.FETCH)) { if (pages.size() > 0) { ScoutDocFetch sdf = new ScoutDocFetch(); RelatedPagesStrategy strategy; if (cmd.hasOption(SOURCE_ALL_PAGES_ID)) { strategy = RelatedPagesStrategy.NO_RELATED_PAGES; } else if (cmd.hasOption(SOURCE_LIST_ID)) { strategy = RelatedPagesStrategy.IMAGES_TEMPLATES_AND_LINKS; } else { throw new IllegalStateException("Page list comes from an unexpected option"); } sdf.execute(pages, strategy); } else if (cmd.hasOption(SOURCE_RECENT_CHANGES_ID)) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.executeRecentChanges(filter); } else if (cmd.hasOption(SOURCE_RSS_ID)) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.executeRss(filter); } else if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.execute(task); } } else { throw new MissingArgumentException("Missing a source"); } } if (operations.contains(Operation.CHECK)) { ScoutDocCheck sdc = new ScoutDocCheck(); List<Check> checks = Lists.newArrayList(); ensureNotSet(cmd, optRecentChange, Operation.CHECK); ensureNotSet(cmd, optRss, Operation.CHECK); if (pages.size() > 0) { checks = sdc.analysePages(pages); } else if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocCheck sdcForTask = new ScoutDocCheck(); checks.addAll(sdcForTask.execute(task)); } } else { throw new MissingArgumentException("Missing a source"); } //output: if (cmd.hasOption(OUTPUT_CHECKSTYLE_ID)) { String fileName = cmd.getOptionValue(OUTPUT_CHECKSTYLE_ID, DEFAULT_CHECKSTYLE_NAME); sdc.writeCheckstyleFile(checks, fileName); } if (cmd.hasOption(OUTPUT_DASHBOARD_ID)) { String folderName = cmd.getOptionValue(OUTPUT_DASHBOARD_ID, DEFAULT_DASHBOARD_NAME); sdc.writeDashboardFiles(checks, folderName); } } if (operations.contains(Operation.CONVERT)) { ensureNotSet(cmd, optAllPages, Operation.CONVERT); ensureNotSet(cmd, optListPages, Operation.CONVERT); ensureNotSet(cmd, optRecentChange, Operation.CONVERT); ensureNotSet(cmd, optRss, Operation.CONVERT); if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocConverter sdc = new ScoutDocConverter(); sdc.execute(task); } } else { throw new MissingArgumentException("Missing a source"); } } } catch (MissingOptionException e) { // Check if it is an error or if optHelp was selected. boolean help = false; try { Options helpOptions = new Options(); helpOptions.addOption(optHelp); CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(helpOptions, args); if (line.hasOption(HELP_ID)) { help = true; } } catch (Exception ex) { ex.printStackTrace(); } if (!help) { System.err.println(e.getMessage()); System.err.flush(); } printHelpAndExit(options); } catch (MissingArgumentException e) { System.err.println(e.getMessage()); printHelpAndExit(options); } catch (ParseException e) { System.err.println("Error while parsing the command line: " + e.getMessage()); System.exit(1); } catch (Exception e) { e.printStackTrace(); } }
From source file:scoutdoc.main.Main.java
private static void ensureNotSet(CommandLine cmd, Option option, Operation operation) throws MissingArgumentException { if (cmd.hasOption(option.getOpt())) { throw new MissingArgumentException("Source <" + option.getLongOpt() + "> is not allowed for the <" + operation.name() + "> operation."); }/*w w w .j a v a2 s. c om*/ }
From source file:scoutdoc.main.Main.java
private static <T extends Enum<T>> List<T> readOptionEnum(CommandLine cmd, Option option, Class<T> c) throws MissingArgumentException { List<T> operations = Lists.newArrayList(); for (String name : cmd.getOptionValues(option.getOpt())) { try {/*from ww w .ja v a 2 s . c o m*/ T operation = Enum.valueOf(c, name); operations.add(operation); } catch (IllegalArgumentException e) { throw new MissingArgumentException( "Unknown value '" + name + "' for '--" + option.getLongOpt() + "'"); } } return operations; }
From source file:scoutdoc.main.Main.java
private static List<Task> readTasks(CommandLine cmd, Option option) throws MissingArgumentException { List<Task> result = Lists.newArrayList(); if (cmd.hasOption(option.getOpt())) { for (String name : cmd.getOptionValues(option.getOpt())) { try { Task task = TaskUtility.toTask(name); result.add(task);/*from w w w . ja v a 2s . c o m*/ } catch (IOException e) { throw new MissingArgumentException("IOException for file '" + name + "' for '--" + option.getLongOpt() + "' : " + e.getMessage()); } } } return result; }
From source file:ws.argo.mcg.GatewayReceiver.java
private static Properties processCommandLine(CommandLine cl) throws RuntimeException, MissingArgumentException { LOGGER.config("Parsing command line values:"); Properties values = new Properties(); if (cl.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GatewayReceiver", getOptions()); return null; }/*from w w w .j ava 2 s .c om*/ // Network Interface if (cl.hasOption("ni")) { String ni = cl.getOptionValue("ni"); values.put("ni", ni); } // Message Repeat values.put("dnr", true); if (cl.hasOption("dnr")) { values.put("dnr", false); LOGGER.info( "*** WARNING - will NOT send on inbound messages to multicast group. This is usually for testing. I hope you are testing."); } // MulticastAddress if (cl.hasOption("ma")) { String ma = cl.getOptionValue("ma"); values.put("ma", ma); } else { throw new MissingArgumentException("Missing multicast address option"); } // MulticastPort if (cl.hasOption("mp")) { try { Integer portNum = Integer.valueOf(cl.getOptionValue("mp")); values.put("mp", portNum); } catch (NumberFormatException e) { throw new RuntimeException("The multicast port number - " + cl.getOptionValue("mp") + " - is not formattable as an integer", e); } } else { throw new MissingArgumentException("Missing multicast port option"); } // MulticastPort if (cl.hasOption("up")) { try { Integer portNum = Integer.valueOf(cl.getOptionValue("up")); values.put("up", portNum); } catch (NumberFormatException e) { throw new RuntimeException("The unicast port number - " + cl.getOptionValue("up") + " - is not formattable as an integer", e); } } else { throw new MissingArgumentException("Missing unicast port option"); } return values; }
From source file:ws.argo.mcg.GatewaySender.java
private static Properties processCommandLine(CommandLine cl) throws RuntimeException, MissingArgumentException { LOGGER.config("Parsing command line values:"); Properties values = new Properties(); if (cl.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GatewaySender", getOptions()); return null; }/*from w w w . j av a2 s . c om*/ values.put("l", false); if (cl.hasOption("l")) { values.put("l", true); } // Network Interface if (cl.hasOption("ni")) { String ni = cl.getOptionValue("ni"); values.put("ni", ni); } // MulticastAddress if (cl.hasOption("ma")) { String ma = cl.getOptionValue("ma"); values.put("ma", ma); } else { throw new MissingArgumentException("Missing multicast address option"); } // MulticastPort if (cl.hasOption("mp")) { try { Integer portNum = Integer.valueOf(cl.getOptionValue("mp")); values.put("mp", portNum); } catch (NumberFormatException e) { throw new RuntimeException("The multicast port number - " + cl.getOptionValue("mp") + " - is not formattable as an integer", e); } } else { throw new MissingArgumentException("Missing multicast port option"); } // MulticastAddress if (cl.hasOption("ua")) { String ua = cl.getOptionValue("ua"); values.put("ua", ua); } else { throw new MissingArgumentException("Missing unicast address option"); } // MulticastPort if (cl.hasOption("up")) { try { Integer portNum = Integer.valueOf(cl.getOptionValue("up")); values.put("up", portNum); } catch (NumberFormatException e) { throw new RuntimeException("The unicast port number - " + cl.getOptionValue("up") + " - is not formattable as an integer", e); } } else { throw new MissingArgumentException("Missing unicast port option"); } return values; }