Changeset 1468 for trunk/yat/utility


Ignore:
Timestamp:
Sep 2, 2008, 4:57:50 PM (13 years ago)
Author:
Peter
Message:

fixes #413

Location:
trunk/yat/utility
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/CommandLine.cc

    r1466 r1468  
    4545
    4646  CommandLine::CommandLine(std::string str)
    47     : description_(str)
     47    : description_(str), free_arg_max_(0)
    4848  {}
    4949
     
    8383        long_options_.find(no_name)==long_options_.end())
    8484      long_options_[no_name] = &option;
     85  }
     86
     87
     88  void CommandLine::allow_free_args(size_t n)
     89  {
     90    free_arg_max_ = n;
    8591  }
    8692
     
    155161        else {
    156162          free_arg_.push_back(*arg);
    157           std::stringstream ss;
    158           ss << ": invalid option -- " << *arg << "\n"
    159              << try_help() << "\n";
    160           throw cmd_error(ss.str());
    161          
     163          if (free_arg_.size()>free_arg_max_) {
     164            std::stringstream ss;
     165            ss << ": invalid option -- " << *arg << "\n"
     166               << try_help() << "\n";
     167            throw cmd_error(ss.str());
     168          }
    162169        }
    163170      }
  • trunk/yat/utility/CommandLine.h

    r1466 r1468  
    107107
    108108    /**
     109       \brief Allow at most \a n free arguments.
     110
     111       An free argument is an argument not associated with an Option,
     112       allowing commandlines such as \code prog foo bar \endcode
     113     */
     114    void allow_free_args(size_t n);
     115
     116    /**
    109117       \brief parse the commandline
    110118
     
    134142    std::string description_;
    135143    std::vector<std::string> free_arg_;
     144    size_t free_arg_max_;
    136145    std::vector<Option*> options_;
    137146    std::map<char, Option*> short_options_;
Note: See TracChangeset for help on using the changeset viewer.