Changeset 1023 for trunk


Ignore:
Timestamp:
Jan 11, 2010, 12:15:47 AM (12 years ago)
Author:
Peter Johansson
Message:

added new cmd option 'anchor-format'. refs #279

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r1016 r1023  
    66  - Gnuplot replaced with plplot (ticket:97)
    77  - new option --format (ticket:438)
     8  - new option --anchor-format (ticket:279)
    89  - new section, `[image]`, in config file (ticket:279 and ticket:405)
    910  - new configure option --with-plplot
  • trunk/bin/Parameter.cc

    r1017 r1023  
    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"),
    5355      config_file_(cmd_, "config-file",
    5456                   "configuration file [<ROOT>/.svndigest/config]"),
     
    99101  Parameter::~Parameter(void)
    100102  {
     103  }
     104
     105
     106  const yat::utility::OptionArg<std::string>&
     107  Parameter::anchor_format(void) const
     108  {
     109    return anchor_format_;
    101110  }
    102111
     
    231240    // don't use argv[0] because user may rename the binary
    232241    cmd_.program_name() = PACKAGE_NAME;
     242    anchor_format_.print_arg("=FMT");
    233243    config_file_.print_arg("=FILE");
    234244    format_.print_arg("=FMT");
  • trunk/bin/Parameter.h

    r1017 r1023  
    4949    Parameter( int argc, char *argv[]);
    5050    virtual ~Parameter(void);
     51    const yat::utility::OptionArg<std::string>& anchor_format(void) const;
    5152    std::string config_file(void) const;
    5253   
     
    7677
    7778    yat::utility::CommandLine cmd_;
     79    yat::utility::OptionArg<std::string> anchor_format_;
    7880    yat::utility::OptionArg<std::string> config_file_;
    7981    yat::utility::OptionSwitch copyright_;
  • trunk/bin/svndigest.cc

    r1017 r1023  
    4949#include <unistd.h>
    5050
     51void option2config(const theplu::yat::utility::OptionArg<std::string>&,
     52                   void (*FUNC)(const std::string&) );
     53
    5154void create_file_struct(std::string stats_type,
    5255                        const theplu::svndigest::Stats& stats);
     
    9194  }
    9295
     96  // just for convenience
     97  Configuration& conf = Configuration::instance();
    9398  // set values from commandline into config object
    9499  try {
     
    100105              << option->format().value() << "' for `--"
    101106              << option->format().long_name() << "'\n"
     107              << e.what() << "\n"
     108              << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
     109    exit(EXIT_FAILURE);
     110  }
     111  try {
     112    if (option->anchor_format().present())
     113      conf.image_anchor_format(option->anchor_format().value());
     114  }
     115  catch (std::runtime_error& e) {
     116    std::cerr << PACKAGE_NAME ": invalid argument `"
     117              << option->anchor_format().value() << "' for `--"
     118              << option->anchor_format().long_name() << "'\n"
    102119              << e.what() << "\n"
    103120              << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
  • trunk/lib/Configuration.cc

    r1017 r1023  
    307307        }
    308308        else if (lhs == "image_format") {
    309           if (rhs!="none" && rhs!="png" && rhs!="svg" && rhs!="pdf") {
    310             throw Config_error(line, "unknown format: " + rhs);
    311           }
    312           image_anchor_format_ = rhs;
     309          try {
     310            image_anchor_format(rhs);
     311          }
     312          catch (std::runtime_error e) {
     313            throw Config_error(line,
     314                               "unknown format: " + rhs + "\n" + e.what());
     315          }
    313316        }
    314317      }
    315318    }
    316319    validate_dictionary();
     320  }
     321
     322
     323  void Configuration::image_anchor_format(const std::string& format)
     324  {
     325    if (format!="none" && format!="pdf" && format!="png" && format!="svg") {
     326      std::ostringstream oss;
     327      oss << "Valid arguments are:\n"
     328          << "  - `none'\n"
     329          << "  - `pdf'\n"
     330          << "  - `png'\n"
     331          << "  - `svg'";
     332      throw std::runtime_error(oss.str());
     333    }
     334    image_anchor_format_ = format;
    317335  }
    318336
  • trunk/lib/Configuration.h

    r1017 r1023  
    7676     */
    7777    const std::string& image_anchor_format(void) const;
     78
     79    /**
     80       \brief set image_anchor_format
     81     */
     82    void image_anchor_format(const std::string&);
    7883
    7984    /**
  • trunk/test/cmd_format_test.sh

    r1022 r1023  
    3232rm -f tmp_stderr
    3333
     34$SVNDIGEST -g --format=svg --anchor-format=svg > tmp_stdout
     35cat tmp_stdout
     36grep 'format = svg' tmp_stdout || exit_fail
     37grep 'anchor_format = svg' tmp_stdout || exit_fail
     38rm -f tmp_stdout
     39
    3440exit_success;
Note: See TracChangeset for help on using the changeset viewer.