- Timestamp:
- Nov 19, 2008, 11:37:11 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/commandline_test.cc
r1632 r1634 112 112 char* av[] = { "test_prog", "--target" }; 113 113 cmd.parse(ac,av); 114 if (target.present() && !verbose.present())114 if (target.present() && target.value() && !verbose.present()) 115 115 suite.err() << "ok\n"; 116 116 else { … … 142 142 else { 143 143 suite.err() << "failed\n"; 144 ok =false; 145 } 146 } 147 148 suite.err() << "Testing OptionSwitch --no-target..."; 149 { 150 int ac = 2; 151 char* av[] = { "test_prog", "--no-target" }; 152 cmd.parse(ac,av); 153 if (target.present() && !target.value()) 154 suite.err() << "ok\n"; 155 else { 156 suite.err() << "failed\n"; 157 if (!target.present()) 158 suite.err() << "target.present() returned false\n"; 159 if (target.value()) 160 suite.err() << "target.value() returned true\n"; 144 161 ok =false; 145 162 } -
trunk/yat/utility/CommandLine.cc
r1487 r1634 74 74 if (option.long_name().size() || option.short_name()) 75 75 options_.push_back(&option); 76 // allow `no-switch' for option `switch'77 OptionSwitch* o = dynamic_cast<OptionSwitch*>(&option);78 std::string no_name = std::string("no-")+option.long_name();79 if (option.long_name().size() && o &&80 !( o->long_name().size()>2 && o->long_name().substr(0,3)=="no-") &&81 long_options_.find(no_name)==long_options_.end())82 long_options_[no_name] = &option;83 76 } 84 77 … … 139 132 std::map<std::string, Option*>::const_iterator 140 133 iter(long_options_.find(key)); 141 if (iter==long_options_.end()) { 142 std::stringstream ss; 143 ss << ": unrecognized option `" << key << "'\n" 144 << try_help(); 134 if (iter!=long_options_.end()) 135 iter->second->parse(arg, arguments.end()); 136 else if (key.size()>3 && key.substr(0,3)=="no-") { 137 iter = long_options_.find(key.substr(3)); 138 if (iter!=long_options_.end()) 139 iter->second->parse(arg, arguments.end()); 140 } 141 else if (iter==long_options_.end()) { 142 ss.str(""); 143 ss << ": unrecognized option `" << key << "'\n" << try_help(); 145 144 throw cmd_error(ss.str()); 146 145 } 147 else148 iter->second->parse(arg, arguments.end());149 146 } 150 147 else if (is_short_option(*arg)) { -
trunk/yat/utility/OptionSwitch.cc
r1487 r1634 40 40 const std::vector<std::string>::iterator& last) 41 41 { 42 if ( long_name().size()>3 && long_name().substr(0,3)=="no-")42 if (first->size()>3 && first->substr(0,3)=="no-") 43 43 switch_=false; 44 44 else
Note: See TracChangeset
for help on using the changeset viewer.