use of com.beust.jcommander.JCommander in project disunity by ata4.
the class Command method run.
@Override
public void run() {
String commandName = commander.getParsedCommand();
if (!commander.getCommands().isEmpty()) {
JCommander command = commander.getCommands().get(commandName);
if (command != null && !command.getObjects().isEmpty()) {
Command commandObj = (Command) command.getObjects().get(0);
commandObj.run();
} else {
// no command selected, show usage
usage();
}
}
}
use of com.beust.jcommander.JCommander in project druid by druid-io.
the class TestNG method privateMain.
/**
* <B>Note</B>: this method is not part of the public API and is meant for internal usage only.
*/
public static TestNG privateMain(String[] argv, ITestListener listener) {
TestNG result = new TestNG();
if (null != listener) {
result.addListener(listener);
}
//
try {
CommandLineArgs cla = new CommandLineArgs();
m_jCommander = new JCommander(cla, argv);
validateCommandLineParameters(cla);
result.configure(cla);
} catch (ParameterException ex) {
exitWithError(ex.getMessage());
}
//
try {
result.run();
} catch (TestNGException ex) {
if (TestRunner.getVerbose() > 1) {
ex.printStackTrace(System.out);
} else {
error(ex.getMessage());
}
result.setStatus(HAS_FAILURE);
}
return result;
}
use of com.beust.jcommander.JCommander in project walle by Meituan-Dianping.
the class Main method main.
public static void main(final String[] args) throws Exception {
final Map<String, IWalleCommand> subCommandList = new HashMap<String, IWalleCommand>();
subCommandList.put("show", new ShowCommand());
subCommandList.put("rm", new RemoveCommand());
subCommandList.put("put", new WriteChannelCommand());
subCommandList.put("batch", new WriteChannelsCommand());
final WalleCommandLine walleCommandLine = new WalleCommandLine();
final JCommander commander = new JCommander(walleCommandLine);
for (Map.Entry<String, IWalleCommand> commandEntry : subCommandList.entrySet()) {
commander.addCommand(commandEntry.getKey(), commandEntry.getValue());
}
try {
commander.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
commander.usage();
System.exit(1);
return;
}
walleCommandLine.parse(commander);
final String parseCommand = commander.getParsedCommand();
if (parseCommand != null) {
subCommandList.get(parseCommand).parse();
}
}
use of com.beust.jcommander.JCommander in project smali by JesusFreke.
the class HelpCommand method run.
public void run() {
JCommander parentJc = commandAncestors.get(commandAncestors.size() - 1);
if (commands == null || commands.isEmpty()) {
System.out.println(new HelpFormatter().width(ConsoleUtil.getConsoleWidth()).format(commandAncestors));
} else {
boolean printedHelp = false;
for (String cmd : commands) {
if (cmd.equals("register-info")) {
printedHelp = true;
String registerInfoHelp = "The --register-info parameter will cause baksmali to generate " + "comments before and after every instruction containing register type " + "information about some subset of registers. This parameter accepts a comma-separated list" + "of values specifying which registers and how much information to include.\n" + " ALL: all pre- and post-instruction registers\n" + " ALLPRE: all pre-instruction registers\n" + " ALLPOST: all post-instruction registers\n" + " ARGS: any pre-instruction registers used as arguments to the instruction\n" + " DEST: the post-instruction register used as the output of the instruction\n" + " MERGE: any pre-instruction register that has been merged from multiple " + "incoming code paths\n" + " FULLMERGE: an extended version of MERGE that also includes a list of all " + "the register types from incoming code paths that were merged";
Iterable<String> lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, ConsoleUtil.getConsoleWidth());
for (String line : lines) {
System.out.println(line);
}
} else if (cmd.equals("input")) {
printedHelp = true;
String registerInfoHelp = "Apks and oat files can contain multiple dex files. In order to " + "specify a particular dex file, the basic syntax is to treat the apk/oat file as a " + "directory. For example, to load the \"classes2.dex\" entry from \"app.apk\", you can " + "use \"app.apk/classes2.dex\".\n" + "\n" + "For ease of use, you can also specify a partial path to the dex file to load. For " + "example, to load a entry named \"/system/framework/framework.jar:classes2.dex\" from " + "\"framework.oat\", you can use any of the following:\n" + "\"framework.oat/classes2.dex\"\n" + "\"framework.oat/framework.jar:classes2.dex\"\n" + "\"framework.oat/framework/framework.jar:classes2.dex\"\n" + "\"framework.oat/system/framework/framework.jar:classes2.dex\"\n" + "\n" + "In some rare cases, an oat file could have entries that can't be differentiated with " + "the above syntax. For example \"/blah/blah.dex\" and \"blah/blah.dex\". In this case, " + "the \"blah.oat/blah/blah.dex\" would match both entries and generate an error. To get " + "around this, you can add double quotes around the entry name to specify an exact entry " + "name. E.g. blah.oat/\"/blah/blah.dex\" or blah.oat/\"blah/blah.dex\" respectively.";
Iterable<String> lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, ConsoleUtil.getConsoleWidth());
for (String line : lines) {
System.out.println(line);
}
} else if (cmd.equals("classpath")) {
printedHelp = true;
String registerInfoHelp = "When deodexing odex/oat files or when using the --register-info " + "option, baksmali needs to load all classes from the framework files on the device " + "in order to fully understand the class hierarchy. There are several options that " + "control how baksmali finds and loads the classpath entries.\n" + "\n" + "L+ devices (ART):\n" + "When deodexing or disassembling a file from an L+ device using ART, you generally " + "just need to specify the path to the boot.oat file via the --bootclasspath/-b " + "parameter. On pre-N devices, the boot.oat file is self-contained and no other files are " + "needed. In N, boot.oat was split into multiple files. In this case, the other " + "files should be in the same directory as the boot.oat file, but you still only need to " + "specify the boot.oat file in the --bootclasspath/-b option. The other files will be " + "automatically loaded from the same directory.\n" + "\n" + "Pre-L devices (dalvik):\n" + "When deodexing odex files from a pre-L device using dalvik, you " + "generally just need to specify the path to a directory containing the framework files " + "from the device via the --classpath-dir/-d option. odex files contain a list of " + "framework files they depend on and baksmali will search for these dependencies in the " + "directory that you specify.\n" + "\n" + "Dex files don't contain a list of dependencies like odex files, so when disassembling a " + "dex file using the --register-info option, and using the framework files from a " + "pre-L device, baksmali will attempt to use a reasonable default list of classpath files " + "based on the api level set via the -a option. If this default list is incorrect, you " + "can override the classpath using the --bootclasspath/-b option. This option accepts a " + "colon separated list of classpath entries. Each entry can be specified in a few " + "different ways.\n" + " - A simple filename like \"framework.jar\"\n" + " - A device path like \"/system/framework/framework.jar\"\n" + " - A local relative or absolute path like \"/tmp/framework/framework.jar\"\n" + "When using the first or second formats, you should also specify the directory " + "containing the framework files via the --classpath-dir/-d option. When using the third " + "format, this option is not needed.\n" + "It's worth noting that the second format matches the format used by Android for the " + "BOOTCLASSPATH environment variable, so you can simply grab the value of that variable " + "from the device and use it as-is.\n" + "\n" + "Examples:\n" + " For an M device:\n" + " adb pull /system/framework/arm/boot.oat /tmp/boot.oat\n" + " baksmali deodex blah.oat -b /tmp/boot.oat\n" + " For an N+ device:\n" + " adb pull /system/framework/arm /tmp/framework\n" + " baksmali deodex blah.oat -b /tmp/framework/boot.oat\n" + " For a pre-L device:\n" + " adb pull /system/framework /tmp/framework\n" + " baksmali deodex blah.odex -d /tmp/framework\n" + " Using the BOOTCLASSPATH on a pre-L device:\n" + " adb pull /system/framework /tmp/framework\n" + " export BOOTCLASSPATH=`adb shell \"echo \\\\$BOOTCLASPATH\"`\n" + " baksmali disassemble --register-info ARGS,DEST blah.apk -b $BOOTCLASSPATH -d " + "/tmp/framework";
Iterable<String> lines = StringWrapper.wrapStringOnBreaks(registerInfoHelp, ConsoleUtil.getConsoleWidth());
for (String line : lines) {
System.out.println(line);
}
} else {
JCommander command = ExtendedCommands.getSubcommand(parentJc, cmd);
if (command == null) {
System.err.println("No such command: " + cmd);
} else {
printedHelp = true;
System.out.println(new HelpFormatter().width(ConsoleUtil.getConsoleWidth()).format(((Command) command.getObjects().get(0)).getCommandHierarchy()));
}
}
}
if (!printedHelp) {
System.out.println(new HelpFormatter().width(ConsoleUtil.getConsoleWidth()).format(commandAncestors));
}
}
}
use of com.beust.jcommander.JCommander in project smali by JesusFreke.
the class Main method main.
public static void main(String[] args) {
Main main = new Main();
JCommander jc = new JCommander(main);
main.jc = jc;
jc.setProgramName("baksmali");
List<JCommander> commandHierarchy = main.getCommandHierarchy();
ExtendedCommands.addExtendedCommand(jc, new DisassembleCommand(commandHierarchy));
ExtendedCommands.addExtendedCommand(jc, new DeodexCommand(commandHierarchy));
ExtendedCommands.addExtendedCommand(jc, new DumpCommand(commandHierarchy));
ExtendedCommands.addExtendedCommand(jc, new HelpCommand(commandHierarchy));
ExtendedCommands.addExtendedCommand(jc, new HlepCommand(commandHierarchy));
ExtendedCommands.addExtendedCommand(jc, new ListCommand(commandHierarchy));
jc.parse(args);
if (main.version) {
version();
}
if (jc.getParsedCommand() == null || main.help) {
main.usage();
return;
}
Command command = (Command) jc.getCommands().get(jc.getParsedCommand()).getObjects().get(0);
command.run();
}
Aggregations