Use args4j for argument parsing

pull/84/head
Andrew Gaul 2014-08-28 12:15:07 -07:00
rodzic f40693f214
commit 1d8dfea9c7
2 zmienionych plików z 36 dodań i 5 usunięć

Wyświetl plik

@ -265,6 +265,11 @@
<version>1.9.28.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>args4j</groupId>
<artifactId>args4j</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>

Wyświetl plik

@ -29,23 +29,43 @@ import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
public final class Main {
private Main() {
throw new AssertionError("intentionally not implemented");
}
private static final class Options {
@Option(name = "--properties",
usage = "S3Proxy configuration (required)")
private File propertiesFile;
@Option(name = "--version", usage = "display version")
private boolean version;
}
public static void main(String[] args) throws Exception {
if (args.length == 1 && args[0].equals("--version")) {
Options options = new Options();
CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (CmdLineException cle) {
usage(parser);
}
if (options.version) {
System.err.println(
Main.class.getPackage().getImplementationVersion());
System.exit(0);
} else if (args.length != 2) {
System.err.println("Usage: s3proxy --properties FILE");
System.exit(1);
} else if (options.propertiesFile == null) {
usage(parser);
}
Properties properties = new Properties();
try (InputStream is = new FileInputStream(new File(args[1]))) {
try (InputStream is = new FileInputStream(options.propertiesFile)) {
properties.load(is);
}
properties.putAll(System.getProperties());
@ -138,4 +158,10 @@ public final class Main {
System.exit(1);
}
}
private static void usage(CmdLineParser parser) {
System.err.println("Usage: s3proxy [options...]");
parser.printUsage(System.err);
System.exit(1);
}
}