remove old option_set.process()
This commit is contained in:
parent
e22487996b
commit
dd3eaa4684
2 changed files with 20 additions and 32 deletions
|
|
@ -28,6 +28,12 @@ namespace ztd
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! @brief option error types
|
//! @brief option error types
|
||||||
|
/*!
|
||||||
|
Values:
|
||||||
|
- unkown_option
|
||||||
|
- takes_no_arg
|
||||||
|
- missing_arg
|
||||||
|
*/
|
||||||
enum error_type { unknown_option, takes_no_arg, missing_arg};
|
enum error_type { unknown_option, takes_no_arg, missing_arg};
|
||||||
|
|
||||||
//! @brief Conctructor
|
//! @brief Conctructor
|
||||||
|
|
@ -45,6 +51,9 @@ namespace ztd
|
||||||
std::string msg;
|
std::string msg;
|
||||||
};
|
};
|
||||||
//! @brief Convert argc/argv into vector<std::string>
|
//! @brief Convert argc/argv into vector<std::string>
|
||||||
|
/*!
|
||||||
|
Does not include argv[0]
|
||||||
|
*/
|
||||||
std::vector<std::string> argVector(int argc, char** argv);
|
std::vector<std::string> argVector(int argc, char** argv);
|
||||||
|
|
||||||
//! @brief Single option object
|
//! @brief Single option object
|
||||||
|
|
@ -104,8 +113,8 @@ namespace ztd
|
||||||
Process arguments through it to extract options
|
Process arguments through it to extract options
|
||||||
|
|
||||||
After processing:
|
After processing:
|
||||||
- for global option settings use find() or parse option_vec
|
- for global option settings use find(), [], or parse through option_vec
|
||||||
- for sequential option settings parse option_sequence
|
- for sequential option settings parse through option_sequence
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class option_set
|
class option_set
|
||||||
|
|
@ -145,44 +154,27 @@ namespace ztd
|
||||||
bool ignore_numbers=false;
|
bool ignore_numbers=false;
|
||||||
//! @brief Stop processing on the first non-option argument
|
//! @brief Stop processing on the first non-option argument
|
||||||
bool stop_on_argument=false;
|
bool stop_on_argument=false;
|
||||||
//! @brief Ignore unknown options (unknown options are in return arguments)
|
//! @brief Ignore unknown options (added to return arguments)
|
||||||
bool ignore_unknown=false;
|
bool ignore_unknown=false;
|
||||||
//! @brief Stop option processing on --
|
//! @brief Stop option processing on \-\-
|
||||||
bool stop_on_doubledash=true;
|
bool stop_on_doubledash=true;
|
||||||
//! @brief Include -- in return arguments if it was encountered
|
//! @brief Include \-\- in return arguments if it was encountered
|
||||||
bool output_doubledash=false;
|
bool output_doubledash=false;
|
||||||
};
|
};
|
||||||
//! @brief Process arguments through the option set
|
//! @brief Process arguments through the option set
|
||||||
/*!
|
/*!
|
||||||
If errors are encountered, exceptions option_error are thrown
|
If errors are encountered, exceptions option_error are thrown
|
||||||
@see struct option_process_arguments
|
@see struct process_arguments
|
||||||
@param arguments vector of string containing arguments and options
|
@param arguments vector of string containing arguments and options
|
||||||
@param behavior behavioral changes for option processing
|
@param behavior behavioral changes for option processing. Optional
|
||||||
@return if @a behavior.stop_on_argument is specified, returns unprocessed arguments\n otherwise, returns leftover arguments that are not options\n
|
@return if @a behavior.stop_on_argument is specified, returns unprocessed arguments\n otherwise, returns leftover arguments that are not options\n
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> process(std::vector<std::string> arguments, struct process_arguments behavior);
|
std::vector<std::string> process(std::vector<std::string> const& arguments, struct process_arguments const& behavior);
|
||||||
//! @brief Process arguments through the option set
|
//! @brief Process arguments through the option set
|
||||||
/*!
|
/*!
|
||||||
@see process(std::vector<std::string> arguments, struct option_process_arguments behavior)
|
@see process(std::vector<std::string> const& arguments, struct process_arguments const& behavior)
|
||||||
*/
|
*/
|
||||||
inline std::vector<std::string> process(int argc, char** argv, struct process_arguments behavior) { return this->process(ztd::argVector(argc, argv), behavior); }
|
inline std::vector<std::string> process(int argc, char** argv, struct process_arguments const& behavior) { return this->process(ztd::argVector(argc, argv), behavior); }
|
||||||
//! @brief Process arguments through the option set
|
|
||||||
/*!
|
|
||||||
For backwards compatibility, use process(std::vector<std::string> arguments, struct option_process_arguments behavior) instead
|
|
||||||
|
|
||||||
If errors are encountered, exceptions option_error are thrown
|
|
||||||
@param arguments vector of string containing arguments and options
|
|
||||||
@param ignore_numbers negative numbers are not considered as options
|
|
||||||
@param stop_on_argument stop processing when encountering a non-option argument
|
|
||||||
@param ignore_unknown don't throw exceptions on unknown options, instead append to return arguments
|
|
||||||
@return if @a stop_on_argument unprocessed arguments\n else leftover arguments that are not options\n
|
|
||||||
*/
|
|
||||||
std::vector<std::string> process(std::vector<std::string> arguments, bool ignore_numbers=false, bool stop_on_argument=false, bool ignore_unknown=false);
|
|
||||||
//! @brief Process arguments through the option set
|
|
||||||
/*!
|
|
||||||
@see process(std::vector<std::string> arguments, bool ignore_numbers, bool stop_on_argument, bool ignore_unknown)
|
|
||||||
*/
|
|
||||||
inline std::vector<std::string> process(int argc, char** argv, bool ignore_numbers=false, bool stop_on_argument=false, bool ignore_unknown=false) { return this->process(ztd::argVector(argc, argv), ignore_numbers, stop_on_argument, ignore_unknown); }
|
|
||||||
|
|
||||||
//! @brief Get option with char name
|
//! @brief Get option with char name
|
||||||
/*! @see option* find(char c)
|
/*! @see option* find(char c)
|
||||||
|
|
|
||||||
|
|
@ -160,11 +160,7 @@ ztd::option* ztd::option_set::find(const std::string& str)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ztd::option_set::process(std::vector<std::string> arguments, bool ignore_numbers, bool stop_on_argument, bool ignore_unknown)
|
std::vector<std::string> ztd::option_set::process(std::vector<std::string> const& arguments, struct ztd::option_set::process_arguments const& behavior)
|
||||||
{
|
|
||||||
return this->process(arguments, {.ignore_numbers=ignore_numbers, .stop_on_argument=stop_on_argument, .ignore_unknown=ignore_unknown});
|
|
||||||
}
|
|
||||||
std::vector<std::string> ztd::option_set::process(std::vector<std::string> arguments, struct ztd::option_set::process_arguments behavior)
|
|
||||||
{
|
{
|
||||||
std::vector<std::string> out;
|
std::vector<std::string> out;
|
||||||
unsigned int i=0;
|
unsigned int i=0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue