Пример #1
0
void TOpts::Validate() const {
    for (TOptsVector::const_iterator i = Opts_.begin(); i != Opts_.end(); ++i) {
        TOpt* opt = i->Get();
        const TOpt::TShortNames& shortNames = opt->GetShortNames();
        for (auto c : shortNames) {
            for (TOptsVector::const_iterator j = i + 1; j != Opts_.end(); ++j) {
                TOpt* nextOpt = j->Get();
                if (nextOpt->CharIs(c))
                    ythrow TConfException() << "option "
                    << NPrivate::OptToString(c)
                    << " is defined more than once";
            }
        }
        const TOpt::TLongNames& longNames = opt->GetLongNames();
        for (const auto& longName : longNames) {
            for (TOptsVector::const_iterator j = i + 1; j != Opts_.end(); ++j) {
                TOpt* nextOpt = j->Get();
                if (nextOpt->NameIs(longName))
                    ythrow TConfException() << "option "
                    << NPrivate::OptToString(longName)
                    << " is defined more than once";
            }
        }
    }
    if (FreeArgsMax_ < FreeArgsMin_) {
        ythrow TConfException() << "FreeArgsMax must be >= FreeArgsMin";
    }
    if (!FreeArgSpecs_.empty() && FreeArgSpecs_.rbegin()->first >= FreeArgsMax_) {
        ythrow TConfException() << "Described args count is greater than FreeArgsMax. Either increase FreeArgsMax or remove unreachable descriptions";
    }
}
Пример #2
0
TOpt& TOpts::AddOption(const TOpt& option) {
    if (option.GetShortNames().empty() && option.GetLongNames().empty())
        ythrow TConfException() << "bad option: no chars, no long names";
    Opts_.push_back(new TOpt(option));
    return *Opts_.back();
}
Пример #3
0
Stroka TOpt::GetName() const {
    if (LongNames_.empty())
        ythrow TConfException() << "no name for option " << this->ToShortString();
    return LongNames_.at(0);
}
Пример #4
0
char TOpt::GetChar() const {
    if (Chars_.empty())
        ythrow TConfException() << "no char for option " << this->ToShortString();
    return Chars_.at(0);
}