From 207533867b13123c4ffe8418f621e9638cf82edc Mon Sep 17 00:00:00 2001 From: Laurent Clouet Date: Mon, 12 Jan 2015 23:09:34 +0100 Subject: [PATCH] Bugfix: if version argument is used on command line, only display the version and them quit --- .../standalone/VersionParameterHandler.java | 48 +++++++++++++++++++ src/com/sheepit/client/standalone/Worker.java | 10 +--- 2 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 src/com/sheepit/client/standalone/VersionParameterHandler.java diff --git a/src/com/sheepit/client/standalone/VersionParameterHandler.java b/src/com/sheepit/client/standalone/VersionParameterHandler.java new file mode 100644 index 0000000..e1de0ac --- /dev/null +++ b/src/com/sheepit/client/standalone/VersionParameterHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Laurent CLOUET + * Author Laurent CLOUET + * + * 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 extends OptionHandler { + public VersionParameterHandler(CmdLineParser parser, OptionDef option, Setter 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; + } +} diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index 45be042..bf0dcdf 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -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);