This commit is contained in:
parent
d0fa2671fa
commit
aa9cdff7a4
|
@ -34,8 +34,8 @@ bool __FloatArgvImpls::optional() const {
|
||||||
return optional_value;
|
return optional_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString args_parse::FloatKeyValue::placeHolder() const {
|
QString args_parse::FloatKeyValue::placeHolder(bool v) const {
|
||||||
if (optional())
|
if (optional() && v)
|
||||||
return QString("[--%1 <%2>]").arg(bindKey(), bindKey());
|
return QString("[--%1 <%2>]").arg(bindKey(), bindKey());
|
||||||
return QString("--%1 <%2>").arg(bindKey(), bindKey());
|
return QString("--%1 <%2>").arg(bindKey(), bindKey());
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ bool FloatKeyValue::parse(const QList<QString> args, int start) {
|
||||||
IndexParam::IndexParam(const QString& place_v, const QString& means)
|
IndexParam::IndexParam(const QString& place_v, const QString& means)
|
||||||
: __ArgvPackImpls(means, ParamType::IndexParam), _place_holder(place_v) { }
|
: __ArgvPackImpls(means, ParamType::IndexParam), _place_holder(place_v) { }
|
||||||
|
|
||||||
QString args_parse::IndexParam::placeHolder() const {
|
QString args_parse::IndexParam::placeHolder(bool v) const {
|
||||||
return QString("<%1>").arg(_place_holder);
|
return QString("<%1>").arg(_place_holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
|
||||||
: __FloatArgvImpls(key, means, opt) {
|
: __FloatArgvImpls(key, means, opt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString args_parse::FloatOption::placeHolder() const {
|
QString args_parse::FloatOption::placeHolder(bool d) const {
|
||||||
if (optional())
|
if (optional() && d)
|
||||||
return QString("[--%1]").arg(bindKey());
|
return QString("[--%1]").arg(bindKey());
|
||||||
return QString("--%1").arg(bindKey());
|
return QString("--%1").arg(bindKey());
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ QString args_parse::MatchMode::explanString() const {
|
||||||
sections << QString(" Switch:");
|
sections << QString(" Switch:");
|
||||||
|
|
||||||
for (auto& item : args_mode) {
|
for (auto& item : args_mode) {
|
||||||
sections << " " + item->placeHolder();
|
sections << " " + item->placeHolder(false);
|
||||||
sections << " " + item->means();
|
sections << " " + item->means();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace args_parse {
|
||||||
* \return ½âÊÍ
|
* \return ½âÊÍ
|
||||||
*/
|
*/
|
||||||
virtual QString means() const = 0;
|
virtual QString means() const = 0;
|
||||||
virtual QString placeHolder() const = 0;
|
virtual QString placeHolder(bool decorate = true) const = 0;
|
||||||
virtual QVariant value() const = 0;
|
virtual QVariant value() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief Æ¥Å䳤¶È.
|
* @brief Æ¥Å䳤¶È.
|
||||||
|
@ -98,7 +98,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 QString placeHolder(bool decorate = true) 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;
|
||||||
};
|
};
|
||||||
|
@ -119,7 +119,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 QString placeHolder(bool decorate = true) 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;
|
||||||
};
|
};
|
||||||
|
@ -136,7 +136,7 @@ namespace args_parse {
|
||||||
virtual ~IndexParam() = default;
|
virtual ~IndexParam() = default;
|
||||||
|
|
||||||
// ͨ¹ý __ArgvPackImpls ¼Ì³Ð
|
// ͨ¹ý __ArgvPackImpls ¼Ì³Ð
|
||||||
virtual QString placeHolder() const override;
|
virtual QString placeHolder(bool decorate = true) 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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,13 +20,7 @@ using namespace example_novel;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace args_parse;
|
using namespace args_parse;
|
||||||
|
|
||||||
/*
|
|
||||||
* nsc --help
|
|
||||||
* nsc -[pw] --path path-to-dir [--out path-to-dir]
|
|
||||||
* opts:
|
|
||||||
* p print-struct 输出整体结构
|
|
||||||
* w print-web 基础的web页面输出格式
|
|
||||||
*/
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
@ -52,6 +46,7 @@ int main(int argc, char* argv[]) {
|
||||||
switch (p_result->modeCode()) {
|
switch (p_result->modeCode()) {
|
||||||
case 0xAu:
|
case 0xAu:
|
||||||
default:
|
default:
|
||||||
|
qDebug().noquote() << u8"命令行参数错误!";
|
||||||
qDebug().noquote() << args_parser.helpDoc();
|
qDebug().noquote() << args_parser.helpDoc();
|
||||||
break;
|
break;
|
||||||
case 0xBu:
|
case 0xBu:
|
||||||
|
|
Loading…
Reference in New Issue