Ejemplo n.º 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";
    }
}
Ejemplo n.º 2
0
TOpt* TOpts::FindCharOption(char c) {
    for (auto& Opt : Opts_) {
        TOpt* opt = Opt.Get();
        if (IsIn(opt->GetShortNames(), c))
            return opt;
    }
    return nullptr;
}
Ejemplo n.º 3
0
TOpt* TOpts::FindCharOption(char c) {
    for (TOptsVector::iterator it = Opts_.begin(); it != Opts_.end(); ++it) {
        TOpt* opt = it->Get();
        if (IsIn(opt->GetShortNames(), c))
            return opt;
    }
    return 0;
}