-
Notifications
You must be signed in to change notification settings - Fork 0
CommandLineOptions
The CommandLineOptions
class is a singleton class that handles command-line options parsing and validation. It encapsulates the Apache Commons CLI library for this purpose.
This class serves as a central point for managing command-line options within the application, allowing for easy addition, retrieval, and parsing of options.
-
options
: Apache Commons CLIOptions
object for regular options. -
firstOptions
: Apache Commons CLIOptions
object for first options like help. -
parser
: Apache Commons CLIParser
object to parse command-line options. -
cmdLine
: Apache Commons CLICommandLine
object holding parsed options. -
appName
: The application's name. -
optionList
: List ofCommandLineOption
objects.
-
Singleton Pattern:
v()
method to get the singleton instance. -
Parsing:
parseArgs(String[] args)
for parsing command-line arguments. -
Option Management:
addOption(CommandLineOption option)
to add an option, andgetOptionValue(String longOpt)
to retrieve an option's value. -
Application Name Management:
getAppName()
andsetAppName(String appName)
to get and set the application name, respectively.
CommandLineOptions clo = CommandLineOptions.v();
CommandLineOptions clo = CommandLineOptions.v();
clo.setAppName("MyApp");
// Adding options
CommandLineOption helpOption = new CommandLineOption("help", "h", "Displays help information.", false, false);
clo.addOption(helpOption);
// Parsing arguments
String[] args = {"-h"};
clo.parseArgs(args);
CommandLineOptions clo = CommandLineOptions.v();
CommandLineOption fileOption = new CommandLineOption("file", "f", "Specify the file path.", true, true);
clo.addOption(fileOption);
String[] args = {"-f", "/path/to/file.txt"};
clo.parseArgs(args);
String filePath = clo.getOptionValue("file"); // Returns "/path/to/file.txt"
Certainly! Below is a typical example demonstrating the use of the CommandLineOptions
class for Android analysis with the AndroSpecter library. This example could be part of a setup for an experiment involving FlowDroid analysis with AndroLibZoo, including connectivity to a Redis server.
// Create and configure the CommandLineOptions instance
CommandLineOptions options = CommandLineOptions.v();
options.setAppName("AndroLibZoo FlowDroid Experiment");
// Set various necessary options
options.addOption(new CommandLineOption("apikey", "a", "AndroZoo API key", true, true));
options.addOption(new CommandLineOption("platforms", "p", "Platform file", true, true));
options.addOption(new CommandLineOption("redis-srv", "s", "Sets the redis server address", true, true));
options.addOption(new CommandLineOption("redis-port", "n", "Sets the redis port to connect to", true, true));
options.addOption(new CommandLineOption("redis-pwd", "w", "Sets the redis password", true, true));
options.addOption(new CommandLineOption("redis-root", "o", "Sets the redis root list/set", true, true));
options.addOption(new CommandLineOption("tool", "t", "The tool to use", true, true));
// Parse the command-line arguments
options.parseArgs(args);
This code snippet demonstrates how the AndroSpecter library can be leveraged to configure various aspects of an Android analysis experiment. It includes setting up the API key, platform file, Redis server configurations, and specifying the analysis tool. The parseArgs
method is then used to parse the command-line arguments, ensuring that all required parameters are properly configured for the experiment.
CommandLineOptions
class simplifies the task of handling command-line options within a Java application, providing an efficient way to add, parse, and retrieve options. It is designed to be used in conjunction with the CommandLineOption
class, enabling an integrated and clear approach to command-line parsing.