This commit is contained in:
codeboss 2024-10-01 18:17:40 +08:00
parent 435d01dde7
commit cae32e3215
2 changed files with 102 additions and 68 deletions

View File

@ -34,7 +34,7 @@ bool __FloatArgvImpl::optional() const {
}
QString args_parse::FloatKeyValue::placeHolder() const {
if(optional())
if (optional())
return QString("[--%1 <%2>]").arg(bindKey(), bindKey());
return QString("--%1 <%2>").arg(bindKey(), bindKey());
}
@ -76,7 +76,7 @@ FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
}
QString args_parse::FloatOption::placeHolder() const {
if(optional())
if (optional())
return QString("[--%1]").arg(bindKey());
return QString("--%1").arg(bindKey());
}
@ -91,34 +91,32 @@ bool FloatOption::parse(const QList<QString> args, int start) {
return args_t == bindKey();
}
namespace args_parse {
class MatchMode {
private:
QList<shared_ptr<IArgvPack>> args_mode;
int code_store;
public:
explicit MatchMode(const QList<shared_ptr<IArgvPack>> mode, int mode_code)
MatchMode::MatchMode(const QList<shared_ptr<IArgvPack>> mode, int mode_code)
:args_mode(mode), code_store(mode_code) { }
/**
* @brief
* @return
*/
int modeCode()const {
/**
* @brief
* @return
*/
int MatchMode::modeCode() const {
return code_store;
}
/**
* @brief
* @return
*/
QList<shared_ptr<IArgvPack>> result() const {
}
/**
* @brief
* @return
*/
QList<shared_ptr<IArgvPack>> MatchMode::result() const {
return args_mode;
}
/**
* @brief
*/
bool parse(const QList<QString>& args, int argv_index, int parse_index) {
}
/**
* @brief
*/
bool MatchMode::parse(const QList<QString>& args, int argv_index, int parse_index) {
if (argv_index >= args.size())
return true;
@ -156,9 +154,8 @@ namespace args_parse {
}
return false;
}
};
}
void ArgsParser::loadMode(int mode_code, const QList<shared_ptr<IArgvPack>>& args_model) {
this->match_modes.append(make_shared<MatchMode>(args_model, mode_code));
}

View File

@ -87,6 +87,13 @@ namespace args_parse {
*/
class ARGSPARSER_EXPORT FloatKeyValue : public __FloatArgvImpl {
public:
/**
* key-value解析单元.
*
* \param key
* \param means
* \param optional
*/
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
virtual ~FloatKeyValue() = default;
@ -101,6 +108,13 @@ namespace args_parse {
*/
class ARGSPARSER_EXPORT FloatOption : public __FloatArgvImpl {
public:
/**
* option解析单元.
*
* \param key
* \param means
* \param optional
*/
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
virtual ~FloatOption() = default;
@ -126,7 +140,30 @@ namespace args_parse {
bool parse(const QList<QString> args, int start) override;
};
class MatchMode;
class ARGSPARSER_EXPORT MatchMode {
private:
QList<shared_ptr<IArgvPack>> args_mode;
int code_store;
public:
explicit MatchMode(const QList<shared_ptr<IArgvPack>> mode, int mode_code);
/**
* @brief
* @return
*/
int modeCode()const;
/**
* @brief
* @return
*/
QList<shared_ptr<IArgvPack>> result() const;
/**
* @brief
*/
bool parse(const QList<QString>& args, int argv_index, int parse_index);
};
class ARGSPARSER_EXPORT ArgsParser {
private:
QList<std::shared_ptr<MatchMode>> match_modes;