Ejemplo n.º 1
0
    const option_description*
    options_description::find_nothrow(const std::string& name, 
                                      bool approx,
                                      bool long_ignore_case,
                                      bool short_ignore_case) const
    {
        shared_ptr<option_description> found;
        bool had_full_match = false;
        vector<string> approximate_matches;
        vector<string> full_matches;
        
        // We use linear search because matching specified option
        // name with the declared option name need to take care about
        // case sensitivity and trailing '*' and so we can't use simple map.
        for(unsigned i = 0; i < m_options.size(); ++i)
        {
            option_description::match_result r = 
                m_options[i]->match(name, approx, long_ignore_case, short_ignore_case);

            if (r == option_description::no_match)
                continue;

            if (r == option_description::full_match)
            {                
                full_matches.push_back(m_options[i]->key(name));
                found = m_options[i];
                had_full_match = true;
            } 
            else 
            {                        
                // FIXME: the use of 'key' here might not
                // be the best approach.
                approximate_matches.push_back(m_options[i]->key(name));
                if (!had_full_match)
                    found = m_options[i];
            }
        }
        if (full_matches.size() > 1) 
            pdalboost::throw_exception(
                ambiguous_option(name, full_matches));
        
        // If we have a full match, and an approximate match,
        // ignore approximate match instead of reporting error.
        // Say, if we have options "all" and "all-chroots", then
        // "--all" on the command line should select the first one,
        // without ambiguity.
        if (full_matches.empty() && approximate_matches.size() > 1)
            pdalboost::throw_exception(
                ambiguous_option(name, approximate_matches));

        return found.get();
    }
Ejemplo n.º 2
0
    const option_description*
    options_description::find_nothrow(const std::string& name, 
                                      bool approx) const
    {
        shared_ptr<option_description> found;
        vector<string> approximate_matches;
        // We use linear search because matching specified option
        // name with the declared option name need to take care about
        // case sensitivity and trailing '*' and so we can't use simple map.
        for(unsigned i = 0; i < m_options.size(); ++i)
        {
            option_description::match_result r = 
                m_options[i]->match(name, approx);

            if (r == option_description::no_match)
                continue;

            // If we have a full patch, and an approximate match,
            // ignore approximate match instead of reporting error.
            // Say, if we have options "all" and "all-chroots", then
            // "--all" on the command line should select the first one,
            // without ambiguity.
            //
            // For now, we don't check the situation when there are 
            // two full matches. 

            if (r == option_description::full_match)
            {
                return m_options[i].get();
            }

            found = m_options[i];
            // FIXME: the use of 'key' here might not
            // be the best approach.
            approximate_matches.push_back(m_options[i]->key(name));
        }
        if (approximate_matches.size() > 1)
            boost::throw_exception(
                ambiguous_option(name, approximate_matches));

        return found.get();
    }