Ignore:
Timestamp:
Jun 2, 2010, 3:56:35 AM (11 years ago)
Author:
Peter Johansson
Message:

refs #307

Splittin the Parameter class into two separate classes and a base
class holding the common parts. The output of '--help' is not sorted
as before otherwise everything should be the same. The sort will
require some ammendment in yat.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/Parameter.cc

    r1023 r1060  
    4848namespace svndigest {
    4949
    50   Parameter::Parameter( int argc, char *argv[])
     50  Parameter::Parameter(void)
    5151    : cmd_( std::string("Mandatory arguments to long options ") +
    5252            std::string("are mandatory for short options too.")),
    53       anchor_format_(cmd_,"anchor-format",
    54                      "override anchor image format defined in config file"),
    5553      config_file_(cmd_, "config-file",
    5654                   "configuration file [<ROOT>/.svndigest/config]"),
    57       copyright_(cmd_, "copyright", "update copyright statement"),
    5855      force_(cmd_, "f,force",
    5956             std::string("if sub-directory named <ROOT> exists in target dire")+
     
    6562                    std::string("ignore cache files and analyze ") +
    6663                    std::string("everything from repository")),
    67       format_(cmd_,"format", "override image format defined in config file"),
    68       report_(cmd_, "report", "create no HTML report", true),
    69       revisions_(cmd_, "revisions",
    70                  "use revision number as time scale instead of dates [dates]"),
    7164      root_(cmd_, "r,root",
    7265            "svn controlled directory to perform statistics on [.]"),
    73       target_(cmd_, "t,target", "output directory [.]"),
    7466      verbose_(cmd_, "v,verbose", "explain what is being done"),
    7567      version_(cmd_, "version", "print version information and exit", &verbose_)
     68  {
     69  }
     70
     71  void Parameter::parse(int argc, char* argv[])
    7672  {
    7773    init();
     
    8480    }
    8581
    86     // set default values
    87     if (!root_.present())
    88       root_.value(".");
    89 
    90     if (!target_.present())
    91       target_.value(".");
    92 
    93     if (!config_file_.present())
    94       config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
     82    set_default();
    9583
    9684    // analyse arguments
     
    10189  Parameter::~Parameter(void)
    10290  {
    103   }
    104 
    105 
    106   const yat::utility::OptionArg<std::string>&
    107   Parameter::anchor_format(void) const
    108   {
    109     return anchor_format_;
    11091  }
    11192
     
    128109      chdir(save_wd.c_str());
    129110
    130       // check target (only if we write report)
    131       if (report()) {
    132         check_existence(target_.value());
    133         check_readable(target_.value());
    134         std::string base_root = file_name(root_.value());
    135         std::string path = concatenate_path(target_.value(),base_root);
    136         if (access_rights(target_.value().c_str(), "w")) {
    137           std::stringstream ss;
    138           ss << "svndigest: cannot create directory `" << path
    139              << "': " << strerror(errno);
    140           throw yat::utility::cmd_error(ss.str());
    141         }
    142         if (node_exist(path) && !force()) {
    143           std::stringstream ss;
    144           ss << "svndigest: cannot create directory `" << path << "' "
    145              << strerror(EEXIST);
    146           throw yat::utility::cmd_error(ss.str());
    147         }
    148         if (chdir(target_.value().c_str())) {
    149           std::stringstream ss;
    150           ss << "svndigest: cannot read `" << target_.value() << "': "
    151              << strerror(errno);
    152           throw yat::utility::cmd_error(ss.str());
    153         }
    154         target_.value(pwd());
    155         chdir(save_wd.c_str());
    156       }
    157111    }
    158112
     
    176130      }
    177131    }
     132    analyse2();
    178133  }
    179134
     
    205160
    206161
    207   bool Parameter::copyright(void) const
    208   {
    209     return copyright_.present();
    210   }
    211 
    212 
    213162  bool Parameter::force(void) const
    214163  {
     
    226175  {
    227176    return ignore_cache_.present();
    228   }
    229 
    230 
    231   const yat::utility::OptionArg<std::string>&
    232   Parameter::format(void) const
    233   {
    234     return format_;
    235177  }
    236178
     
    240182    // don't use argv[0] because user may rename the binary
    241183    cmd_.program_name() = PACKAGE_NAME;
    242     anchor_format_.print_arg("=FMT");
    243184    config_file_.print_arg("=FILE");
    244     format_.print_arg("=FMT");
    245185    root_.print_arg("=ROOT");
    246     target_.print_arg("=TARGET");
    247186    std::stringstream ss;
    248187    ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n"
    249188       << PACKAGE << " home page: <" << PACKAGE_URL << ">.\n";
    250189    help_.post_arguments() = ss.str();
    251     help_.synopsis() =
    252       "Generate statistical report for a subversion repository\n";
    253   }
    254 
    255 
    256   bool Parameter::report(void) const
    257   {
    258     return report_.value();
    259   }
    260 
    261 
    262   bool Parameter::revisions(void) const
    263   {
    264     return revisions_.present();
     190    init2();
    265191  }
    266192
     
    271197  }
    272198
    273  
    274   std::string Parameter::targetdir(void) const
    275   {
    276     return target_.value();
    277   }
    278 
    279  
     199  void Parameter::set_default(void)
     200  {
     201    if (!root_.present())
     202      root_.value(".");
     203
     204    if (!config_file_.present())
     205      config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
     206
     207    set_default2();
     208  }
     209
     210
    280211  bool Parameter::verbose(void) const
    281212  {
Note: See TracChangeset for help on using the changeset viewer.