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

Cmdline/picocli #168

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13'
compile group: 'com.jcraft', name: 'jsch', version: '0.1.54'
compile group: 'org.jfree', name: 'jfreechart', version: '1.5.0'
compile group: 'info.picocli', name: 'picocli', version: '3.8.1'
testCompile 'junit:junit:4.12'
}

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/net/atomique/ksar/CmdLineArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2018 The kSAR Project. All rights reserved.
* See the LICENSE file in the project root for more information.
*/

package net.atomique.ksar;

import picocli.CommandLine.Option;

public class CmdLineArgs {

@Option(names = "-input", description = "sar file to be processed")
private String filename;

@Option(names = "-help", description = "show usage", help = true)
private boolean help;

@Option(names = "-version", description = "print version information")
private boolean version = false;

@Option(names = "-test", description = "debug mode")
private boolean debug = false;

public String getFilename() {
return filename;
}

public boolean isHelp() {
return help;
}

public boolean isVersion() {
return version;
}

public boolean isDebug() {
return debug;
}

}
51 changes: 25 additions & 26 deletions src/main/java/net/atomique/ksar/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008 The kSAR Project. All rights reserved.
* Copyright 2018 The kSAR Project. All rights reserved.
* See the LICENSE file in the project root for more information.
*/

Expand All @@ -8,6 +8,7 @@
import net.atomique.ksar.ui.Desktop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.util.ResourceBundle;

Expand Down Expand Up @@ -61,8 +62,6 @@ public void run() {
}

public static void main(String[] args) {
int i = 0;
String arg;

log.info("ksar Version : {}", VersionNumber.getVersionString());
log.info("Java runtime Version : {}", System.getProperty("java.runtime.version"));
Expand All @@ -79,30 +78,30 @@ public static void main(String[] args) {
config = Config.getInstance();
globaloptions = GlobalOptions.getInstance();

CmdLineArgs cmdl_args = new CmdLineArgs();
new CommandLine(cmdl_args).parse(args);

if (args.length > 0) {
while (i < args.length && args[i].startsWith("-")) {
arg = args[i++];
if ("-version".equals(arg)) {
show_version();
System.exit(0);
}
if ("-help".equals(arg)) {
usage();
continue;
}
if ("-test".equals(arg)) {
GlobalOptions.setDodebug(true);
continue;
}
if ("-input".equals(arg)) {
if (i < args.length) {
GlobalOptions.setCLfilename(args[i++]);
} else {
exit_error(resource.getString("INPUT_REQUIRE_ARG"));
}
continue;
}
if (cmdl_args.isVersion()) {
show_version();
System.exit(0);
}

if (cmdl_args.isHelp()) {
usage();
System.exit(0);
}

if (cmdl_args.isDebug()) {
GlobalOptions.setDodebug(true);
} else {
GlobalOptions.setDodebug(false);
}

if (cmdl_args.getFilename() != null) {
if (cmdl_args.getFilename().isEmpty()) {
exit_error(resource.getString("INPUT_REQUIRE_ARG"));
} else {
GlobalOptions.setCLfilename(cmdl_args.getFilename());
}
}

Expand Down