- Timestamp:
- Sep 12, 2009, 4:53:45 PM (14 years ago)
- Location:
- trunk/bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Parameter.cc
r795 r820 48 48 49 49 Parameter::Parameter( int argc, char *argv[]) 50 : cmd_( 51 "Mandatory arguments to long options are mandatory for short options too.") 50 : cmd_( std::string("Mandatory arguments to long options ") + 51 std::string("are mandatory for short options too.")), 52 config_file_(cmd_, "config-file", 53 "configuration file [<ROOT>/.svndigest/config]"), 54 copyright_(cmd_, "copyright", "update copyright statement"), 55 force_(cmd_, "f,force", 56 std::string("if sub-directory named <ROOT> exists in target dire")+ 57 std::string("ctory, remove sub-directory before writing results")), 58 generate_config_(cmd_, "g,generate-config", 59 "write configuration to standard output"), 60 help_(cmd_), 61 ignore_cache_(cmd_, "ignore-cache", 62 std::string("ignore cache files and analyze ") + 63 std::string("everything from repository")), 64 report_(cmd_, "report", "create no HTML report", true), 65 revisions_(cmd_, "revisions", 66 "use revision number as time scale instead of dates [dates]"), 67 root_(cmd_, "r,root", 68 "svn controlled directory to perform statistics on [.]"), 69 target_(cmd_, "t,target", "output directory [.]"), 70 verbose_(cmd_, "v,verbose", "explain what is being done"), 71 version_(cmd_, "version", "print version information and exit", &verbose_) 52 72 { 53 73 init(); … … 61 81 62 82 // set default values 63 if (!root_ ->present())64 root_ ->value(".");65 66 if (!target_ ->present())67 target_ ->value(".");68 69 if (!config_file_ ->present())70 config_file_ ->value(concatenate_path(root_->value(),".svndigest/config"));83 if (!root_.present()) 84 root_.value("."); 85 86 if (!target_.present()) 87 target_.value("."); 88 89 if (!config_file_.present()) 90 config_file_.value(concatenate_path(root_.value(),".svndigest/config")); 71 91 72 92 // analyse arguments … … 77 97 Parameter::~Parameter(void) 78 98 { 79 delete config_file_;80 delete copyright_;81 delete force_;82 delete generate_config_;83 delete help_;84 delete ignore_cache_;85 delete report_;86 delete revisions_;87 delete root_;88 delete target_;89 delete verbose_;90 delete version_;91 99 } 92 100 … … 98 106 // check root but not if -g option given 99 107 if (!generate_config()) { 100 check_existence(root_ ->value());101 check_readable(root_ ->value());102 if (chdir(root_ ->value().c_str())) {108 check_existence(root_.value()); 109 check_readable(root_.value()); 110 if (chdir(root_.value().c_str())) { 103 111 std::stringstream ss; 104 ss << "svndigest: cannot read `" << root_ ->value() << "': "112 ss << "svndigest: cannot read `" << root_.value() << "': " 105 113 << strerror(errno); 106 114 throw yat::utility::cmd_error(ss.str()); 107 115 } 108 root_ ->value(pwd());116 root_.value(pwd()); 109 117 chdir(save_wd.c_str()); 110 118 111 119 // check target (only if we write report) 112 120 if (report()) { 113 check_existence(target_ ->value());114 check_readable(target_ ->value());115 std::string base_root = file_name(root_ ->value());116 std::string path = concatenate_path(target_ ->value(),base_root);117 if (access_rights(target_ ->value().c_str(), "w")) {121 check_existence(target_.value()); 122 check_readable(target_.value()); 123 std::string base_root = file_name(root_.value()); 124 std::string path = concatenate_path(target_.value(),base_root); 125 if (access_rights(target_.value().c_str(), "w")) { 118 126 std::stringstream ss; 119 127 ss << "svndigest: cannot create directory `" << path … … 127 135 throw yat::utility::cmd_error(ss.str()); 128 136 } 129 if (chdir(target_ ->value().c_str())) {137 if (chdir(target_.value().c_str())) { 130 138 std::stringstream ss; 131 ss << "svndigest: cannot read `" << target_ ->value() << "': "139 ss << "svndigest: cannot read `" << target_.value() << "': " 132 140 << strerror(errno); 133 141 throw yat::utility::cmd_error(ss.str()); 134 142 } 135 target_ ->value(pwd());143 target_.value(pwd()); 136 144 chdir(save_wd.c_str()); 137 145 } … … 141 149 struct stat nodestat; 142 150 // true also if there is a broken symlink named... 143 bool config_exists = !lstat(config_file_ ->value().c_str(), &nodestat);151 bool config_exists = !lstat(config_file_.value().c_str(), &nodestat); 144 152 // the latter case in order to catch broken symlink 145 if (config_file_ ->present() || config_exists)153 if (config_file_.present() || config_exists) 146 154 // throws if file does not exists 147 check_existence(config_file_ ->value());155 check_existence(config_file_.value()); 148 156 if (config_exists) { 149 157 // throws if file is not readable 150 check_readable(config_file_ ->value());151 stat(config_file_ ->value().c_str(), &nodestat);158 check_readable(config_file_.value()); 159 stat(config_file_.value().c_str(), &nodestat); 152 160 if (!S_ISREG(nodestat.st_mode)) { 153 161 std::stringstream ss; 154 ss << "svndigest: `" << config_file_ ->value()162 ss << "svndigest: `" << config_file_.value() 155 163 << "' is not a regular file"; 156 164 throw yat::utility::cmd_error(ss.str()); … … 182 190 std::string Parameter::config_file(void) const 183 191 { 184 return config_file_ ->value();192 return config_file_.value(); 185 193 } 186 194 … … 188 196 bool Parameter::copyright(void) const 189 197 { 190 return copyright_ ->present();198 return copyright_.present(); 191 199 } 192 200 … … 194 202 bool Parameter::force(void) const 195 203 { 196 return force_ ->present();204 return force_.present(); 197 205 } 198 206 … … 200 208 bool Parameter::generate_config(void) const 201 209 { 202 return generate_config_ ->present();210 return generate_config_.present(); 203 211 } 204 212 … … 206 214 bool Parameter::ignore_cache(void) const 207 215 { 208 return ignore_cache_ ->present();216 return ignore_cache_.present(); 209 217 } 210 218 … … 214 222 // don't use argv[0] because user may rename the binary 215 223 cmd_.program_name() = PACKAGE_NAME; 216 config_file_ =new yat::utility::OptionArg<std::string>(cmd_, "config-file",217 "configuration file [<ROOT>/.svndigest/config]");218 config_file_->print_arg("=FILE");224 config_file_.print_arg("=FILE"); 225 root_.print_arg("=ROOT"); 226 target_.print_arg("=TARGET"); 219 227 std::stringstream ss; 220 copyright_ = new yat::utility::OptionSwitch(cmd_, "copyright",221 "update copyright statement");222 223 ss << "if sub-directory named <ROOT> exists in target directory, remove "224 << "sub-directory before writing results";225 force_ = new yat::utility::OptionSwitch(cmd_, "f,force", ss.str());226 ss.str("");227 228 help_ = new yat::utility::OptionHelp(cmd_);229 generate_config_ =230 new yat::utility::OptionSwitch(cmd_, "g,generate-config",231 "write configuration file to standard output");232 233 ss.str("");234 ss << "ignore cache files and analyze everything from repository";235 ignore_cache_ = new yat::utility::OptionSwitch(cmd_, "ignore-cache", ss.str());236 237 report_ = new yat::utility::OptionSwitch(cmd_, "report", "create no HTML report", true);238 239 ss.str("");240 ss << "use revision numbers as time scale instead of dates [dates]";241 revisions_ = new yat::utility::OptionSwitch(cmd_, "revisions", ss.str());242 243 root_=244 new yat::utility::OptionArg<std::string>(cmd_, "r,root",245 "svn controlled directory to perform statistics on [.]");246 root_->print_arg("=ROOT");247 target_ = new yat::utility::OptionArg<std::string>(cmd_, "t,target",248 "output directory [.]");249 target_->print_arg("=TARGET");250 251 verbose_ = new yat::utility::OptionSwitch(cmd_, "v,verbose", "explain what is being done");252 version_ = new OptionVersion(cmd_, "version",253 "print version information and exit", verbose_);254 255 ss.str("");256 228 ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n"; 257 help_ ->post_arguments() = ss.str();258 help_ ->synopsis() =229 help_.post_arguments() = ss.str(); 230 help_.synopsis() = 259 231 "Generate statistical report for a subversion repository\n"; 260 232 } … … 263 235 bool Parameter::report(void) const 264 236 { 265 return report_ ->value();237 return report_.value(); 266 238 } 267 239 … … 269 241 bool Parameter::revisions(void) const 270 242 { 271 return revisions_ ->present();243 return revisions_.present(); 272 244 } 273 245 … … 275 247 std::string Parameter::root(void) const 276 248 { 277 return root_ ->value();249 return root_.value(); 278 250 } 279 251 … … 281 253 std::string Parameter::targetdir(void) const 282 254 { 283 return target_ ->value();255 return target_.value(); 284 256 } 285 257 … … 287 259 bool Parameter::verbose(void) const 288 260 { 289 return verbose_ ->present();261 return verbose_.present(); 290 262 } 291 263 -
trunk/bin/Parameter.h
r795 r820 24 24 */ 25 25 26 #include "OptionVersion.h" 27 26 28 #include "yat/CommandLine.h" 27 29 #include "yat/OptionArg.h" 30 #include "yat/OptionHelp.h" 31 #include "yat/OptionSwitch.h" 32 28 33 29 34 #include <string> … … 70 75 71 76 yat::utility::CommandLine cmd_; 72 yat::utility::OptionArg<std::string> *config_file_;73 yat::utility::OptionSwitch *copyright_;74 yat::utility::OptionSwitch *force_;75 yat::utility::OptionSwitch *generate_config_;76 yat::utility::OptionHelp *help_;77 yat::utility::OptionSwitch *ignore_cache_;78 yat::utility::OptionSwitch *report_;79 yat::utility::OptionSwitch *revisions_;80 yat::utility::OptionArg<std::string> *root_;81 yat::utility::OptionArg<std::string> *target_;82 yat::utility::OptionSwitch *verbose_;83 OptionVersion *version_;77 yat::utility::OptionArg<std::string> config_file_; 78 yat::utility::OptionSwitch copyright_; 79 yat::utility::OptionSwitch force_; 80 yat::utility::OptionSwitch generate_config_; 81 yat::utility::OptionHelp help_; 82 yat::utility::OptionSwitch ignore_cache_; 83 yat::utility::OptionSwitch report_; 84 yat::utility::OptionSwitch revisions_; 85 yat::utility::OptionArg<std::string> root_; 86 yat::utility::OptionArg<std::string> target_; 87 yat::utility::OptionSwitch verbose_; 88 OptionVersion version_; 84 89 85 90 };
Note: See TracChangeset
for help on using the changeset viewer.