Changeset 1069 for trunk/bin


Ignore:
Timestamp:
Jun 6, 2010, 5:10:43 AM (11 years ago)
Author:
Peter Johansson
Message:

refs #307. Structure main function in svndigest.cc. Create a function copy_option2config.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r1068 r1069  
    3131#include "main_utility.h"
    3232#include "rmdirhier.h"
     33#include <sstream>
    3334#include "Stats.h"
    3435#include "StatsCollection.h"
     
    5051#include <unistd.h>
    5152
     53using namespace theplu;
     54using namespace svndigest;
     55void copy_option2config(const svndigestParameter&, Configuration&);
     56
    5257void create_file_struct(std::string stats_type,
    5358                        const theplu::svndigest::Stats& stats);
     
    5560int main( int argc, char* argv[])
    5661{
    57   using namespace theplu;
    58   using namespace svndigest;
    5962
    6063  // Reading commandline options
     
    7275  try {
    7376    load_config(option.config_file());
     77    copy_option2config(option, Configuration::instance());
    7478  }
    7579  catch (std::runtime_error& e) {
     
    8185  Configuration& config = Configuration::instance();
    8286  // set values from commandline into config object
    83   try {
    84     if (option.format().present())
    85       Configuration::instance().image_format(option.format().value());
    86   }
    87   catch (std::runtime_error& e) {
    88     std::cerr << PACKAGE_NAME ": invalid argument `"
    89               << option.format().value() << "' for `--"
    90               << option.format().long_name() << "'\n"
    91               << e.what() << "\n"
    92               << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
    93     exit(EXIT_FAILURE);
    94   }
    95   try {
    96     if (option.anchor_format().present())
    97       config.image_anchor_format(option.anchor_format().value());
    98   }
    99   catch (std::runtime_error& e) {
    100     std::cerr << PACKAGE_NAME ": invalid argument `"
    101               << option.anchor_format().value() << "' for `--"
    102               << option.anchor_format().long_name() << "'\n"
    103               << e.what() << "\n"
    104               << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
    105     exit(EXIT_FAILURE);
    106   }
    107  
    10887  // write configuration
    10988  if (option.generate_config()) {
     
    244223  exit(EXIT_SUCCESS);       // normal exit
    245224}
     225
     226
     227void copy_option2config(const svndigestParameter& option, Configuration& config)
     228{
     229  try {
     230    if (option.format().present())
     231      Configuration::instance().image_format(option.format().value());
     232  }
     233  catch (std::runtime_error& e) {
     234    std::stringstream ss;
     235    ss << "invalid argument `"
     236       << option.format().value() << "' for `--"
     237       << option.format().long_name() << "'\n"
     238       << e.what() << "\n"
     239       << "Try `svndigest --help' for more information.\n";
     240    throw std::runtime_error(ss.str());
     241  }
     242  try {
     243    if (option.anchor_format().present())
     244      config.image_anchor_format(option.anchor_format().value());
     245  }
     246  catch (std::runtime_error& e) {
     247    std::stringstream ss;
     248    ss << "invalid argument `"
     249       << option.anchor_format().value() << "' for `--"
     250       << option.anchor_format().long_name() << "'\n"
     251       << e.what() << "\n"
     252       << "Try `svndigest --help' for more information.\n";
     253    throw std::runtime_error(ss.str());
     254  }
     255}
     256
    246257
    247258  void create_file_struct(std::string stats_type,
Note: See TracChangeset for help on using the changeset viewer.