This commit is contained in:
parent
0de21ee189
commit
435d01dde7
|
@ -33,6 +33,12 @@ bool __FloatArgvImpl::optional() const {
|
||||||
return optional_value;
|
return optional_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString args_parse::FloatKeyValue::placeHolder() const {
|
||||||
|
if(optional())
|
||||||
|
return QString("[--%1 <%2>]").arg(bindKey(), bindKey());
|
||||||
|
return QString("--%1 <%2>").arg(bindKey(), bindKey());
|
||||||
|
}
|
||||||
|
|
||||||
int FloatKeyValue::matchLenth() const {
|
int FloatKeyValue::matchLenth() const {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +51,12 @@ bool FloatKeyValue::parse(const QList<QString> args, int start) {
|
||||||
return args_t == bindKey();
|
return args_t == bindKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexParam::IndexParam(const QString& means) : __ArgvPackImpls(means, ParamType::IndexParam) { }
|
IndexParam::IndexParam(const QString& place_v, const QString& means)
|
||||||
|
: __ArgvPackImpls(means, ParamType::IndexParam), _place_holder(place_v) { }
|
||||||
|
|
||||||
|
QString args_parse::IndexParam::placeHolder() const {
|
||||||
|
return QString("<%1>").arg(_place_holder);
|
||||||
|
}
|
||||||
|
|
||||||
int IndexParam::matchLenth() const {
|
int IndexParam::matchLenth() const {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -64,6 +75,12 @@ FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
|
||||||
setValue(u8"0");
|
setValue(u8"0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString args_parse::FloatOption::placeHolder() const {
|
||||||
|
if(optional())
|
||||||
|
return QString("[--%1]").arg(bindKey());
|
||||||
|
return QString("--%1").arg(bindKey());
|
||||||
|
}
|
||||||
|
|
||||||
int FloatOption::matchLenth() const {
|
int FloatOption::matchLenth() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,19 @@ namespace args_parse {
|
||||||
class IArgvPack {
|
class IArgvPack {
|
||||||
public:
|
public:
|
||||||
virtual ~IArgvPack() = default;
|
virtual ~IArgvPack() = default;
|
||||||
|
/**
|
||||||
|
* 参数包类型.
|
||||||
|
*
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
virtual ParamType paramType() const = 0;
|
virtual ParamType paramType() const = 0;
|
||||||
|
/**
|
||||||
|
* @brief 参数解释.
|
||||||
|
*
|
||||||
|
* \return 解释
|
||||||
|
*/
|
||||||
virtual QString means() const = 0;
|
virtual QString means() const = 0;
|
||||||
|
virtual QString placeHolder() const = 0;
|
||||||
virtual QString value() const = 0;
|
virtual QString value() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief 匹配长度.
|
* @brief 匹配长度.
|
||||||
|
@ -80,6 +90,7 @@ namespace args_parse {
|
||||||
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
|
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
|
||||||
virtual ~FloatKeyValue() = default;
|
virtual ~FloatKeyValue() = default;
|
||||||
|
|
||||||
|
virtual QString placeHolder() const override;
|
||||||
virtual int matchLenth() const override;
|
virtual int matchLenth() const override;
|
||||||
bool parse(const QList<QString> args, int start) override;
|
bool parse(const QList<QString> args, int start) override;
|
||||||
};
|
};
|
||||||
|
@ -93,6 +104,7 @@ namespace args_parse {
|
||||||
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
|
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
|
||||||
virtual ~FloatOption() = default;
|
virtual ~FloatOption() = default;
|
||||||
|
|
||||||
|
virtual QString placeHolder() const override;
|
||||||
virtual int matchLenth() const override;
|
virtual int matchLenth() const override;
|
||||||
bool parse(const QList<QString> args, int start) override;
|
bool parse(const QList<QString> args, int start) override;
|
||||||
};
|
};
|
||||||
|
@ -101,11 +113,15 @@ namespace args_parse {
|
||||||
* 序列索引参数.
|
* 序列索引参数.
|
||||||
*/
|
*/
|
||||||
class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls {
|
class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls {
|
||||||
|
private:
|
||||||
|
QString _place_holder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IndexParam(const QString &means);
|
explicit IndexParam(const QString & place_v, const QString &means);
|
||||||
virtual ~IndexParam() = default;
|
virtual ~IndexParam() = default;
|
||||||
|
|
||||||
// 通过 __ArgvPackImpls 继承
|
// 通过 __ArgvPackImpls 继承
|
||||||
|
virtual QString placeHolder() const override;
|
||||||
int matchLenth() const override;
|
int matchLenth() const override;
|
||||||
bool parse(const QList<QString> args, int start) override;
|
bool parse(const QList<QString> args, int start) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,12 +30,12 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
args_parse::ArgsParser args_parser;
|
args_parse::ArgsParser args_parser;
|
||||||
QList<std::shared_ptr<args_parse::IArgvPack>> args_mode;
|
QList<std::shared_ptr<args_parse::IArgvPack>> args_mode;
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"³ÌÐòÃû³Æ");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"nsc", u8"³ÌÐòÃû³Æ");
|
||||||
args_mode << std::make_shared<args_parse::FloatOption>(u8"--help", u8"帮助");
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--help", u8"帮助");
|
||||||
args_parser.loadMode(0x000Au, args_mode);
|
args_parser.loadMode(0x000Au, args_mode);
|
||||||
|
|
||||||
args_mode.clear();
|
args_mode.clear();
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"³ÌÐòÃû³Æ");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"nsc", u8"³ÌÐòÃû³Æ");
|
||||||
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--path", u8"源代码目录");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--path", u8"源代码目录");
|
||||||
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--dest", u8"生成目录");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--dest", u8"生成目录");
|
||||||
args_mode << std::make_shared<args_parse::FloatOption>(u8"--html", u8"生成html文件格式取代AST", true);
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--html", u8"生成html文件格式取代AST", true);
|
||||||
|
|
Loading…
Reference in New Issue