
Public Member Functions | |
| CmdLineArgs () | |
| void | reset () |
| void | registerOption (String name, int minValuesCount) |
| void | registerOption (CmdLineRegisteredOption opt) |
| void | parseArgs (String[] args) |
| String[] | getAllArgs () |
| CmdLineOption[] | getRecognizedArgs () |
| boolean | isSpecified (CmdLineRegisteredOption clo) |
| String[] | getValues (CmdLineOption clo) |
Private Member Functions | |
| boolean | isKey (String[] args, int index) |
Private Attributes | |
| Map | m_registeredOptions |
| LinkedHashMap | m_options |
Deals with commandline options (String[] args), for example to merge several sets of option specifications.
An option consists of a key arg and 0...many value arguments. The method parseArgs will attempt to guess which arguments are keys and which are values, e.g. looking for a "-" prefix. This class can therefore be used for unknown sets of options.
To avoid fooling the algorithm with weird values (like "-273"), the expected option keys with their minimum number of values can be specified using the registerOption methods. This mechanism can later be extended to allow validation of required arguments.
TODO: logging and error handling
| alma::acs::util::CmdLineArgs::CmdLineArgs | ( | ) | [inline] |
References reset().
| String [] alma::acs::util::CmdLineArgs::getAllArgs | ( | ) | [inline] |
Returns all arguments (both options and values). If arguments were parsed more than once, the values from a later call overwrite earlier ones. Options and values that could not be distinguished during parsing appear in the original order.
References alma::acs::util::CmdLineOption::getName(), and m_options.
Referenced by alma::acs::container::corba::OrbConfigurator::getOptions(), alma::acs::util::CmdLineArgsTest::testBadArgsForUnregisteredOptions(), and alma::acs::util::CmdLineArgsTest::testUnregisteredOptions().
| CmdLineOption [] alma::acs::util::CmdLineArgs::getRecognizedArgs | ( | ) | [inline] |
Gets all arguments that were recognized by the parser. This includes arguments registered before parsing, as well as arguments recognized automatically. The values for these args can be obtained from getValues(CmdLineOption).
References m_options.
Referenced by alma::acs::util::CmdLineArgsTest::testBadArgsForUnregisteredOptions(), and alma::acs::util::CmdLineArgsTest::testUnregisteredOptions().
| String [] alma::acs::util::CmdLineArgs::getValues | ( | CmdLineOption | clo | ) | [inline] |
References m_options.
Referenced by alma::acs::config::validators::ConfigFileFinder::configureFromArgs(), alma::acs::logging::dialogs::main::CommandLineParser::parse(), alma::acs::logtools::monitor::LogMonitor::parseCmdLineArgs(), alma::acs::logging::tools::LogAssistant::parseCommandLine(), alma::acs::releasedoc::ProcessCvs2clOutput::setOptions(), alma::acs::container::AcsContainerRunner::setOptions(), alma::acs::util::CmdLineArgsTest::testBadArgsForUnregisteredOptions(), alma::acs::util::CmdLineArgsTest::testRegisteredOptions(), and alma::acs::util::CmdLineArgsTest::testUnregisteredOptions().
| boolean alma::acs::util::CmdLineArgs::isKey | ( | String[] | args, | |
| int | index | |||
| ) | [inline, private] |
Decides whether args[index] is a key or a value. Future implementations might need to look at args[other indices], that's why the full array is supplied.
| args | ||
| index |
References m_registeredOptions.
Referenced by parseArgs().
| boolean alma::acs::util::CmdLineArgs::isSpecified | ( | CmdLineRegisteredOption | clo | ) | [inline] |
Returns true if the given option clo appeared in the argument lists that were passed to parseArgs; false otherwise.
| clo |
References m_options.
Referenced by alma::acs::config::validators::ConfigFileFinder::configureFromArgs(), alma::acs::logging::dialogs::main::CommandLineParser::parse(), alma::acs::logtools::monitor::LogMonitor::parseCmdLineArgs(), alma::acs::logging::tools::LogAssistant::parseCommandLine(), alma::acs::releasedoc::ProcessCvs2clOutput::setOptions(), alma::acs::container::AcsContainerRunner::setOptions(), alma::acs::util::CmdLineArgsTest::testRegisteredOptions(), and alma::acs::util::CmdLineArgsTest::testRegisteredOptionsWithAlternativeNames().
| void alma::acs::util::CmdLineArgs::parseArgs | ( | String[] | args | ) | [inline] |
If called more than once without calling reset() in between, the options are merged in the style of a Map.
| args |
References alma::acs::util::CmdLineRegisteredOption::getMinValueCount(), alma::acs::util::CmdLineOption::getName(), isKey(), m_options, and m_registeredOptions.
Referenced by alma::acs::config::validators::ConfigFileFinder::configureFromArgs(), alma::acs::logging::dialogs::main::CommandLineParser::parse(), alma::acs::logtools::monitor::LogMonitor::parseCmdLineArgs(), alma::acs::logging::tools::LogAssistant::parseCommandLine(), alma::acs::releasedoc::ProcessCvs2clOutput::setOptions(), alma::acs::container::corba::OrbConfigurator::setOptions(), alma::acs::container::AcsContainerRunner::setOptions(), alma::acs::util::CmdLineArgsTest::testBadArgsForUnregisteredOptions(), alma::acs::util::CmdLineArgsTest::testRegisteredOptions(), alma::acs::util::CmdLineArgsTest::testRegisteredOptionsWithAlternativeNames(), and alma::acs::util::CmdLineArgsTest::testUnregisteredOptions().
| void alma::acs::util::CmdLineArgs::registerOption | ( | CmdLineRegisteredOption | opt | ) | [inline] |
| void alma::acs::util::CmdLineArgs::registerOption | ( | String | name, | |
| int | minValuesCount | |||
| ) | [inline] |
Referenced by alma::acs::config::validators::ConfigFileFinder::configureFromArgs(), alma::acs::container::corba::OrbConfigurator::OrbConfigurator(), alma::acs::logging::dialogs::main::CommandLineParser::parse(), alma::acs::logtools::monitor::LogMonitor::parseCmdLineArgs(), alma::acs::logging::tools::LogAssistant::parseCommandLine(), alma::acs::releasedoc::ProcessCvs2clOutput::setOptions(), alma::acs::container::AcsContainerRunner::setOptions(), alma::acs::util::CmdLineArgsTest::testRegisteredOptions(), and alma::acs::util::CmdLineArgsTest::testRegisteredOptionsWithAlternativeNames().
| void alma::acs::util::CmdLineArgs::reset | ( | ) | [inline] |
References m_options, and m_registeredOptions.
Referenced by CmdLineArgs().
LinkedHashMap alma::acs::util::CmdLineArgs::m_options [private] |
Referenced by getAllArgs(), getRecognizedArgs(), getValues(), isSpecified(), parseArgs(), and reset().
Map alma::acs::util::CmdLineArgs::m_registeredOptions [private] |
Referenced by isKey(), parseArgs(), registerOption(), and reset().
1.6.2