Ignore:
Timestamp:
Nov 14, 2010, 6:34:10 AM (11 years ago)
Author:
Peter Johansson
Message:

rewrite svndigest-copy-cache in C++. closes #463

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/Parameter.cc

    r1264 r1293  
    2525#include "Parameter.h"
    2626
    27 #include "lib/OptionVersion.h"
    28 #include "lib/utility.h" // to avoid inclusion of yat file
     27#include "lib/utility.h"
    2928
    3029#include "yat/ColumnStream.h"
     
    4948
    5049  Parameter::Parameter(void)
    51     : cmd_( std::string("Mandatory arguments to long options ") +
    52             std::string("are mandatory for short options too.")),
    53       config_file_(cmd_, "config-file",
     50    : config_file_(cmd_, "config-file",
    5451                   "configuration file [<ROOT>/.svndigest/config]"),
    5552      generate_config_(cmd_, "g,generate-config",
    5653                       "write configuration to standard output"),
    57       help_(cmd_),
    5854      ignore_cache_(cmd_, "ignore-cache",
    5955                    std::string("ignore cache files and analyze ") +
    60                     std::string("everything from repository")),
    61       root_(cmd_, "r,root",
    62             "svn controlled directory to perform statistics on [.]"),
    63       verbose_(cmd_, "v,verbose", "explain what is being done"),
    64       version_(cmd_, "version", "print version information and exit", &verbose_)
     56                    std::string("everything from repository"))
    6557  {
    66   }
    67 
    68 
    69   void Parameter::parse(int argc, char* argv[])
    70   {
    71     init();
    72     cmd_.parse(argc, argv);
    73     set_default();
    74     // analyse arguments
    75     analyse();
    7658  }
    7759
     
    8264
    8365
    84   void Parameter::analyse(void)
     66  void Parameter::analyse1(void)
    8567  {
    8668    std::string save_wd = pwd();
     
    8870    // check root but not if -g option given
    8971    if (!generate_config()) {
    90       check_existence(root_.value());
    91       check_readable(root_.value());
    92       check_is_dir(root_.value());
    93 
    94       chdir(root_.value());
    95       root_full_ = pwd();
    96       chdir(save_wd);
    97 
    98       // take care of when root is a symlink (see ticket #477)
    99       struct stat stats;
    100       lstat(root_.value().c_str(), &stats);
    101       if (S_ISLNK(stats.st_mode))
    102         root_basename_ = file_name(root_.value());
    103       else
    104         root_basename_ = file_name(root_full_);
     72      analyse_root(root_.value());
    10573    }
    10674
     
    12896
    12997
    130   void Parameter::check_existence(std::string path) const
    131   {
    132     if (node_exist(path))
    133       return;
    134     std::stringstream ss;
    135     ss << cmd_.program_name() << ": cannot stat '" << path << "': "
    136        << strerror(errno);
    137     throw yat::utility::cmd_error(ss.str());
    138   }
    139 
    140  
    141   void Parameter::check_is_dir(std::string path) const
    142   {
    143     if (node_exist(path)) {
    144       struct stat buf;
    145       stat(path.c_str(), &buf);
    146       if (S_ISDIR(buf.st_mode))
    147         return;
    148     }
    149     std::stringstream ss;
    150     ss << cmd_.program_name() << ": '" << path << "': "
    151        << strerror(errno);
    152     throw yat::utility::cmd_error(ss.str());
    153   }
    154 
    155  
    156   void Parameter::check_readable(std::string path) const
    157   {
    158     if (!access_rights(path, "r"))
    159       return;
    160     std::stringstream ss;
    161     ss << cmd_.program_name() << ": cannot open '" << path << "': "
    162        << strerror(errno);
    163     throw yat::utility::cmd_error(ss.str());
    164   }
    165  
    166 
    16798  std::string Parameter::config_file(void) const
    16899  {
     
    183114
    184115
    185   void Parameter::init(void)
     116  void Parameter::init1(void)
    186117  {
    187     // we like the options sorted alphabetically
    188     cmd_.sort();
    189118    config_file_.print_arg("=FILE");
    190     root_.print_arg("=ROOT");
    191     std::stringstream ss;
    192     ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n"
    193        << PACKAGE << " home page: <" << PACKAGE_URL << ">.\n";
    194     help_.post_arguments() = ss.str();
    195119    init2();
    196120  }
    197121
    198122
    199   std::string Parameter::root(void) const
     123  void Parameter::set_default1(void)
    200124  {
    201     return root_full_;
    202   }
    203 
    204 
    205   const std::string& Parameter::root_basename(void) const
    206   {
    207     assert(root_basename_.size());
    208     return root_basename_;
    209   }
    210 
    211 
    212   void Parameter::set_default(void)
    213   {
    214     if (!root_.present())
    215       root_.value(".");
    216 
    217125    if (!config_file_.present())
    218126      config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
     
    222130
    223131
    224   bool Parameter::verbose(void) const
    225   {
    226     return verbose_.present();
    227   }
    228 
    229 
    230132}} // of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.