Changeset 625 for trunk/bin/Parameter.cc
- Timestamp:
- Apr 24, 2008, 12:44:52 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/Parameter.cc
r620 r625 42 42 43 43 Parameter::Parameter( int argc, char *argv[]) 44 { 45 defaults(); 44 : config_file_(""), copyright_(false), force_(false), 45 generate_config_(false), ignore_cache_(false), report_(true), 46 revisions_(false), root_("."), targetdir_("."), verbose_(false) 47 { 46 48 for (int i=1; i<argc; ++i) { 47 49 bool ok=false; … … 54 56 if (myargv=="--config-file"){ 55 57 if (value.size()) { 56 config_file_ = value;58 config_file_.value()= value; 57 59 ok=true; 58 60 } 59 61 else if (++i<argc){ 60 config_file_ = std::string(argv[i]);62 config_file_.value()= std::string(argv[i]); 61 63 ok=true; 62 64 } 63 65 } 64 66 else if (myargv=="--copyright"){ 65 copyright_ =true;67 copyright_.value()=true; 66 68 ok=true; 67 69 } 68 70 else if (myargv=="-f" || myargv=="--force"){ 69 force_ =true;71 force_.value()=true; 70 72 ok=true; 71 73 } 72 74 else if (myargv=="-g" || myargv=="--generate-config"){ 73 generate_config_ =true;75 generate_config_.value()=true; 74 76 ok=true; 75 77 } … … 79 81 } 80 82 else if (myargv=="--ignore-cache"){ 81 ignore_cache_ =true;83 ignore_cache_.value()=true; 82 84 ok=true; 83 85 } 84 86 else if (myargv=="-r" || myargv=="--root"){ 85 87 if (value.size()) { 86 root_ = value;88 root_.value()= value; 87 89 ok=true; 88 90 } 89 91 else if (++i<argc){ 90 root_ = std::string(argv[i]);92 root_.value()= std::string(argv[i]); 91 93 ok=true; 92 94 } 93 95 } 94 96 else if (myargv=="--report") { 95 report_ =true;97 report_.value()=true; 96 98 ok=true; 97 99 } 98 100 else if (myargv=="--no-report") { 99 report_ =false;101 report_.value()=false; 100 102 ok=true; 101 103 } 102 104 else if (myargv=="--revisions") { 103 revisions_ =true;105 revisions_.value()=true; 104 106 ok=true; 105 107 } 106 108 else if (myargv=="-t" || myargv=="--target"){ 107 109 if (value.size()) { 108 targetdir_ = value;110 targetdir_.value()= value; 109 111 ok=true; 110 112 } 111 113 else if (++i<argc){ 112 targetdir_ = std::string(argv[i]);114 targetdir_.value()= std::string(argv[i]); 113 115 ok=true; 114 116 } 115 117 } 116 118 else if (myargv=="-v" || myargv=="--verbose"){ 117 verbose_ =true;119 verbose_.value()=true; 118 120 ok=true; 119 121 } 120 122 else if (myargv=="--version"){ 121 version _=true;122 ok=true;123 version(); 124 exit(0); 123 125 } 124 126 else if (myargv=="-vf" || myargv=="-fv"){ 125 verbose_ =true;126 force_ =true;127 verbose_.value()=true; 128 force_.value()=true; 127 129 ok=true; 128 130 } … … 133 135 } 134 136 135 if (version_){136 version(verbose_);137 exit(0);138 }139 137 analyse(); 140 138 } … … 147 145 string workdir(pwd()); // remember current working directory (cwd). 148 146 149 bool root_ok = node_exist(root_) && !access_rights(root_, "r"); 147 bool root_ok = ( node_exist(root_.value()) && 148 !access_rights(root_.value(), "r") ); 150 149 151 150 if (root_ok) { 152 151 // Check that root_ is a directory 153 152 struct stat nodestat; 154 stat(root_. c_str(), &nodestat);153 stat(root_.value().c_str(), &nodestat); 155 154 if (!S_ISDIR(nodestat.st_mode)) 156 throw runtime_error(string("svndigest: accessing `") + root_ +155 throw runtime_error(string("svndigest: accessing `") + root_.value() + 157 156 "': Not a directory."); 158 157 } 159 158 160 159 // Checking that root_ exists and retrieve the absolute path to root_ 161 if (!root_ok || chdir(root_. c_str()))162 throw runtime_error(string("svndigest: Root directory (") + root_ +160 if (!root_ok || chdir(root_.value().c_str())) 161 throw runtime_error(string("svndigest: Root directory (") + root_.value() + 163 162 ") access failed."); 164 root_ = pwd();163 root_.value() = pwd(); 165 164 166 165 … … 172 171 // Checking that targetdir_ exists and retrieve the absolute path 173 172 // to targetdir_ 174 if (chdir(targetdir_. c_str()))175 throw runtime_error(string("svndigest: Target directory (") + targetdir_ +176 ") access failed.");177 targetdir_ = pwd();173 if (chdir(targetdir_.value().c_str())) 174 throw runtime_error(string("svndigest: Target directory (") + 175 targetdir_.value() + ") access failed."); 176 targetdir_.value() = pwd(); 178 177 // Checking write permissions for targetdir_ 179 if (access_rights(targetdir_ ,"w"))178 if (access_rights(targetdir_.value(),"w")) 180 179 throw runtime_error(string("svndigest: No write permission on target ") + 181 "directory (" + targetdir_ +").");180 "directory (" + targetdir_.value() +")."); 182 181 183 182 // return back to cwd … … 191 190 { 192 191 // not default 193 if (!config_file_. empty())194 return config_file_ ;192 if (!config_file_.value().empty()) 193 return config_file_.value(); 195 194 196 195 // default behaviour … … 199 198 200 199 201 void Parameter::defaults(void) 202 { 203 config_file_ = ""; 204 copyright_=false; 205 force_=false; 206 generate_config_=false; 207 ignore_cache_=false; 208 report_=true; 209 revisions_=false; 210 root_="."; 211 targetdir_="."; 212 verbose_=false; 213 version_=false; 214 } 215 216 217 void Parameter::help(void) 218 { 219 defaults(); 220 200 void Parameter::help(void) const 201 { 221 202 ColumnStream cs(std::cout, 1); 222 203 cs.width(0)=79; … … 249 230 << "instead of dates [dates]\n" 250 231 << "-r, --root=ROOT\tsvn controlled directory to perform " 251 << "statistics calculation on [" << root_ << "]\n" 252 << "-t, --target=TARGET\toutput directory [" << targetdir_ << "]\n" 232 << "statistics calculation on [" << root_.default_value() << "]\n" 233 << "-t, --target=TARGET\toutput directory [" 234 << targetdir_.default_value() << "]\n" 253 235 << "-v, --verbose\texplain what is being done\n" 254 236 << " --version\tprint version information and exit\n";
Note: See TracChangeset
for help on using the changeset viewer.