src/components/command_line.cpp
/**
   * Parse and validate passed arguments and flags
   */
Parse and validate passed arguments and flags
Parse and validate passed arguments and flags
void parser::parse(const string& input, const string& input_next) {
    auto skipped = m_skipnext;
    if (m_skipnext) {
      m_skipnext = false;
      if (!input_next.empty()) {
        return;
      }
    }
    for (auto&& opt : m_opts) {
      if (is(input, opt.flag, opt.flag_long)) {
        if (opt.token.empty()) {
          m_optvalues.insert(make_pair(opt.flag_long.substr(2), ""));
        } else {
          auto value = parse_value(input, input_next, opt.values);
          m_skipnext = (value == input_next);
          m_optvalues.insert(make_pair(opt.flag_long.substr(2), value));
        }
        return;
      }
    }
    if (skipped) {
      return;
    } else if (input[0] != '-') {
      m_posargs.emplace_back(input);
    } else {
      throw argument_error("Unrecognized option " + input);
    }
  }
void parser :: parse ( const string & input , const string & input_next ) { auto skipped = m_skipnext ; if ( m_skipnext ) { m_skipnext = false ; if ( ! input_next . empty ( ) ) { return ; } } for ( auto && opt : m_opts ) { if ( is ( input , opt . flag , opt . flag_long ) ) { if ( opt . token . empty ( ) ) { m_optvalues . insert ( make_pair ( opt . flag_long . substr ( 2 ) , " " ) ) ; } else { auto value = parse_value ( input , input_next , opt . values ) ; m_skipnext = ( value == input_next ) ; m_optvalues . insert ( make_pair ( opt . flag_long . substr ( 2 ) , value ) ) ; } return ; } } if ( skipped ) { return ; } else if ( input [ 0 ] != ' ' ) { m_posargs . emplace_back ( input ) ; } else { throw argument_error ( " " + input ) ; } }
Parse and validate passed arguments and flags
Parse and validate passed arguments and flags