Changeset 1468
- Timestamp:
- Sep 2, 2008, 4:57:50 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/commandline_test.cc
r1466 r1468 57 57 suite.add(test_failures(suite)); 58 58 suite.add(test_option_name_clash(suite)); 59 //suite.add(test_free_arg(suite));59 suite.add(test_free_arg(suite)); 60 60 } 61 61 catch (std::runtime_error& e) { … … 459 459 460 460 CommandLine cmd; 461 cmd.allow_free_args(2); 461 462 OptionHelp help(cmd); 462 463 int ac = 3; -
trunk/yat/utility/CommandLine.cc
r1466 r1468 45 45 46 46 CommandLine::CommandLine(std::string str) 47 : description_(str) 47 : description_(str), free_arg_max_(0) 48 48 {} 49 49 … … 83 83 long_options_.find(no_name)==long_options_.end()) 84 84 long_options_[no_name] = &option; 85 } 86 87 88 void CommandLine::allow_free_args(size_t n) 89 { 90 free_arg_max_ = n; 85 91 } 86 92 … … 155 161 else { 156 162 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 } 162 169 } 163 170 } -
trunk/yat/utility/CommandLine.h
r1466 r1468 107 107 108 108 /** 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 /** 109 117 \brief parse the commandline 110 118 … … 134 142 std::string description_; 135 143 std::vector<std::string> free_arg_; 144 size_t free_arg_max_; 136 145 std::vector<Option*> options_; 137 146 std::map<char, Option*> short_options_;
Note: See TracChangeset
for help on using the changeset viewer.