Bugfix: if version argument is used on command line, only display the version and them quit

This commit is contained in:
Laurent Clouet
2015-01-12 23:09:34 +01:00
parent c174e574f1
commit 207533867b
2 changed files with 50 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2015 Laurent CLOUET
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
*
* This program 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; version 2
* of the License.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package com.sheepit.client.standalone;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
import com.sheepit.client.Configuration;
public class VersionParameterHandler<T> extends OptionHandler<T> {
public VersionParameterHandler(CmdLineParser parser, OptionDef option, Setter<? super T> setter) {
super(parser, option, setter);
}
@Override
public int parseArguments(Parameters params) throws CmdLineException {
Configuration config = new Configuration(null, "", "");
System.out.println("Version: " + config.getJarVersion());
System.exit(0);
return 0;
}
@Override
public String getDefaultMetaVariable() {
return null;
}
}

View File

@@ -83,8 +83,8 @@ public class Worker {
@Option(name = "-ui", usage = "Specify the user interface to use, default 'text', available 'oneline', 'text'", required = false)
private String ui_type = "text";
@Option(name = "--version", usage = "Display application version", required = false)
private boolean display_version = false;
@Option(name = "--version", usage = "Display application version", required = false, handler = VersionParameterHandler.class)
private VersionParameterHandler versionHandler;
public static void main(String[] args) {
new Worker().doMain(args);
@@ -104,12 +104,6 @@ public class Worker {
return;
}
if (display_version) {
Configuration config = new Configuration(null, "", "");
System.out.println("Version: " + config.getJarVersion());
return;
}
ComputeType compute_method = ComputeType.CPU_ONLY;
Configuration config = new Configuration(null, login, password);
config.setPrintLog(print_log);