Changeset 1178
- Timestamp:
- Feb 27, 2008, 8:24:31 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/commandline_test.cc
r1000 r1178 369 369 OptionFile inclones(cmd, "clones", "file containing clones"); 370 370 OptionFile indata(cmd, "data", "data to merge"); 371 OptionFile out(cmd, "o,out", "data to merge", true, false, "w"); 371 372 OptionSwitch help(cmd, "h,help", "display this help and exit"); 372 373 … … 374 375 { 375 376 int ac = 2; 376 char* av[] = { "test_prog", "-h" }; 377 char* av[] = { "test_prog", "--clones", "commandline_test.cc" 378 "--data", "commandline_test.cc", "-o", 379 "commandline_test.cc"}; 377 380 cmd.parse(ac,av); 378 381 error << "ok\n"; -
trunk/yat/utility/CommandLine.cc
r1000 r1178 25 25 26 26 #include "ColumnStream.h" 27 #include "Exception.h" 27 28 #include "Option.h" 28 29 #include "OptionSwitch.h" … … 115 116 ss << ": unrecognized option `" << key << "'\n" 116 117 << try_help(); 117 throw std::runtime_error(ss.str());118 throw cmd_error(ss.str()); 118 119 } 119 120 else … … 129 130 ss << ": invalid option -- " << (*arg)[i] << "\n" 130 131 << try_help() << "\n"; 131 throw std::runtime_error(ss.str());132 throw cmd_error(ss.str()); 132 133 } 133 134 else … … 139 140 std::mem_fun(&Option::validate)); 140 141 } 141 catch ( std::runtime_error& e){142 catch (cmd_error& e){ 142 143 std::stringstream ss; 143 144 ss << program_name_ << ": " << e.what(); 144 throw std::runtime_error(ss.str());145 throw cmd_error(ss.str()); 145 146 } 146 147 -
trunk/yat/utility/CommandLine.h
r1000 r1178 24 24 02111-1307, USA. 25 25 */ 26 27 #include "TypeInfo.h"28 26 29 27 #include <cctype> … … 62 60 cmd.parse(argc, argv); 63 61 } 64 catch ( std::runtime_error e){62 catch (cmd_error e){ 65 63 std::cout << e.what() << std::endl; 66 64 return 1; … … 112 110 \brief parse the commandline 113 111 114 throw std::runtime_error if an error is detected.112 throw cmd_error if an error is detected. 115 113 */ 116 114 void parse(int argc, char* argv[]); -
trunk/yat/utility/Exception.h
r1000 r1178 34 34 namespace yat { 35 35 namespace utility { 36 37 /** 38 \brief Class used for error reported from Commandline or Option. 39 */ 40 class cmd_error : public std::runtime_error 41 { 42 public: 43 inline cmd_error(std::string message) 44 : std::runtime_error(message) {} 45 }; 46 36 47 37 48 /** -
trunk/yat/utility/Option.cc
r1000 r1178 84 84 present_=true; 85 85 do_parse(first, last); 86 std::cerr << "parsed " << long_name() << std::endl; 86 87 } 87 88 … … 147 148 void Option::validate() 148 149 { 150 std::cerr << "validate: " << long_name() << std::endl; 149 151 do_validate(); 150 152 } -
trunk/yat/utility/OptionArg.h
r1125 r1178 27 27 #include "Option.h" 28 28 #include "CommandLine.h" 29 #include "Exception.h" 29 30 30 #include <stdexcept>31 31 #include <string> 32 32 #include <sstream> … … 87 87 ss << "option requires an argument -- " << short_name() << "\n" 88 88 << cmd().try_help(); 89 throw std::runtime_error(ss.str());89 throw cmd_error(ss.str()); 90 90 } 91 91 if (first+1==last ) { … … 94 94 ss << "option `--" << long_name() << "' requires an argument\n" 95 95 << cmd().try_help(); 96 throw std::runtime_error(ss.str());96 throw cmd_error(ss.str()); 97 97 } 98 98 else { … … 100 100 ss << "option requires an argument -- " << short_name() << "\n" 101 101 << cmd().try_help(); 102 throw std::runtime_error(ss.str());102 throw cmd_error(ss.str()); 103 103 } 104 104 } … … 125 125 std::stringstream sstr(rhs); 126 126 sstr << ": invalid argument"; 127 throw std::runtime_error(sstr.str());127 throw cmd_error(sstr.str()); 128 128 } 129 129 } … … 142 142 ss << "' not given\n"; 143 143 ss << cmd().try_help(); 144 throw std::runtime_error(ss.str());144 throw cmd_error(ss.str()); 145 145 } 146 146 do_validate2(); -
trunk/yat/utility/OptionFile.cc
r1014 r1178 23 23 24 24 #include "OptionFile.h" 25 #include "Exception.h" 25 26 #include "FileUtil.h" 26 27 27 #include <stdexcept>28 28 #include <string> 29 29 … … 46 46 void OptionFile::do_validate2() const 47 47 { 48 std::cerr << "OptionFile:: do_validate2 " << std::endl; 48 49 if (!present()) 49 50 return; 50 51 FileUtil fu(value().c_str()); 52 std::cerr << "check exist" << std::endl; 51 53 if (exist_ && !fu.exists()){ 52 54 std::stringstream ss; 53 55 ss << "cannot stat `" << value() << "': No such file or directory"; 54 throw std::runtime_error(ss.str());56 throw cmd_error(ss.str()); 55 57 } 58 std::cerr << "check perm" << std::endl; 56 59 if (fu.permissions(bits_)) { 57 60 // Peter, this loop is stupid but I wanna differentiate the error message … … 60 63 std::stringstream ss; 61 64 ss << "cannot stat `" << value() << "': No such file or directory"; 62 throw std::runtime_error(ss.str());65 throw cmd_error(ss.str()); 63 66 } 64 67 else if (*iter=='w' && fu.permissions("w")){ … … 66 69 ss << "cannot create file `" << value() 67 70 << "': Permission denied"; 68 throw std::runtime_error(ss.str());71 throw cmd_error(ss.str()); 69 72 } 70 73 } 71 74 std::stringstream ss; 72 75 ss << value() << ": Permission denied"; 73 throw std::runtime_error(ss.str());76 throw cmd_error(ss.str()); 74 77 } 75 78 }
Note: See TracChangeset
for help on using the changeset viewer.