Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcm4che-tools-common: Patch Apache CLI PosixParser to recognize '--' as end of the options mark #126

Merged
merged 4 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.UID;
import org.dcm4che3.data.Attributes;
Expand Down Expand Up @@ -341,7 +340,7 @@ public static void addPriorityOption(Options opts) {

public static CommandLine parseComandLine(String[] args, Options opts,
ResourceBundle rb2, Class<?> clazz) throws ParseException {
CommandLineParser parser = new PosixParser();
CommandLineParser parser = new DetectEndOfOptionsPosixParser();
CommandLine cl = parser.parse(opts, args);
if (cl.hasOption("h")) {
HelpFormatter formatter = new HelpFormatter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is part of dcm4che, an implementation of DICOM(TM) in
* Java(TM), hosted at https://github.com/gunterze/dcm4che.
*
* The Initial Developer of the Original Code is
* J4Care.
* Portions created by the Initial Developer are Copyright (C) 2015-2017
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* See @authors listed below
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
*/

package org.dcm4che3.tool.common;

import org.apache.commons.cli.*;

import java.util.Arrays;
import java.util.Properties;

/**
* @author Gunter Zeilinger <gunterze@gmail.com>
* @since Jun 2017
*/
public class DetectEndOfOptionsPosixParser extends PosixParser {

@Override
public CommandLine parse(Options opts, String[] args, Properties props, boolean stopAtNonOption)
throws ParseException {
int i = args.length;
while (--i >= 0 && !"--".equals(args[i]))
;
CommandLine cl = super.parse(opts, i < 0 ? args : Arrays.copyOf(args, i), props, stopAtNonOption);
if (i >= 0)
while (++i < args.length)
cl.getArgList().add(args[i]);
return cl;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
usage=findscu [options] -c <aet>@<host>:<port> [dcmfile_in...]
usage=findscu [options] -c <aet>@<host>:<port> [--] [<dicom-file>|<xml-file>...]
try=Try `findscu --help' for more information.
description=\n\
The findscu application implements a Service Class User (SCU) for the \
Expand All @@ -7,7 +7,7 @@ Procedure Step, the Hanging Protocol Query/Retrieve and the Color Palette \
Query/Retrieve Service Class. findscu only supports query functionality using \
the C-FIND message. It sends query keys to an Service Class Provider (SCP) \
and waits for responses. Query keys can be specified in DICOM binary file(s) \
dcmfile_in or xml file(s) dcmfile_in.xml or by options -m and -r. \
or DICOM XML file(s) -- <dicom-file>|<xml-file>... or by options -m and -r. \
For reference, sample files (patient.xml, study.xml, series.xml, instance.xml, mwl.xml) \
with query keys on PATIENT, STUDY, SERIES, IMAGE and MWL levels \
are provided in etc/findscu folder. \n\-\n\
Expand All @@ -17,7 +17,7 @@ Example 1: findscu -c DCMQRSCP@localhost:11112 -m PatientName=Doe^John -m StudyD
-m ModalitiesInStudy=CT\n\
=> Query Query/Retrieve Service Class Provider DCMQRSCP listening on local port 11112 for CT Studies \
for Patient John Doe since 2011-05-10 \n\-\n\
Example 2: findscu -c DCMQRSCP@localhost:11112 /etc/findscu/study.xml \n\
Example 2: findscu -c DCMQRSCP@localhost:11112 -- /etc/findscu/study.xml \n\
=> Query Query/Retrieve Service Class Provider DCMQRSCP listening on local port 11112 with query keys \
provided in /etc/findscu/study.xml file
model=specifies Information Model. Supported names: PatientRoot, StudyRoot, PatientStudyOnly, \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
usage=movescu [options] -c <aet>@<host>:<port> --dest <aet> [dcmfile_in...]
usage=movescu [options] -c <aet>@<host>:<port> --dest <aet> [--] [<dicom-file>...]
try=Try `movescu --help' for more information.
description=\n\
The movescu application implements a Service Class User (SCU) for the Query/Retrieve, the \
Composite Instance Root Retrieve, the Composite Instance Retrieve Without Bulk Data, the \
Hanging Protocol Query/Retrieve and the Color Palette Query/Retrieve Service Class. movescu \
only supports retrieve functionality using the C-MOVE message. It sends matching keys to an \
Service Class Provider (SCP) and waits for responses. Matching keys can be specified in \
DICOM file(s) dcmfile_in or by options -m.\n\-\n\
DICOM file(s) -- <dicom-file>... or by options -m.\n\-\n\
Options:
example=-\n\
Examples:\n\
Expand Down