-
Notifications
You must be signed in to change notification settings - Fork 0
CommandLineOption
Jordan Samhi edited this page Aug 22, 2023
·
1 revision
The CommandLineOption
class represents a command line option. It encapsulates properties like the long and short forms, description, whether it requires an argument, whether it's mandatory, and its value.
The class serves as a representation of a command line option and is structured to provide all essential information related to a command line argument.
-
longOpt
: Long form of the option, e.g., "help". -
shortOpt
: Short form of the option, e.g., "h". -
description
: Description of the option. -
hasArg
: Flag to indicate if the option requires an argument. -
isRequired
: Flag to indicate if the option is mandatory. -
value
: Value of the option if provided on the command line.
- Constructors, getters, and setters are provided for all attributes.
CommandLineOption helpOption = new CommandLineOption("help", "h", "Displays help information.", false, false);
// Create an option
CommandLineOption fileOption = new CommandLineOption("file", "f", "Specify the file path.", true, true);
// Modify the option
fileOption.setDescription("Specify the path to the input file.");
fileOption.setRequired(false);
// Create an option
CommandLineOption verboseOption = new CommandLineOption("verbose", "v", "Enable verbose mode.", false, false);
// Query the option
String description = verboseOption.getDescription(); // Returns "Enable verbose mode."
boolean isRequired = verboseOption.isRequired(); // Returns false
These examples demonstrate the utility of the CommandLineOption
class in handling command line options, making it easier to manage and utilize these within a program.