Re: [Boost-bugs] [Boost C++ Libraries] #2982: Required Arguments

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2982: Required Arguments
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-10-22 17:38:39


#2982: Required Arguments
------------------------------------------------+---------------------------
 Reporter: David Doria <daviddoria@…> | Owner: vladimir_prus
     Type: Feature Requests | Status: new
Milestone: Boost 1.39.0 | Component: program_options
  Version: Boost Development Trunk | Severity: Not Applicable
 Keywords: Required Arguments |
------------------------------------------------+---------------------------

Comment(by s.ochsenknecht@…):

 I find it useful, so I added a patch which implements the required() flag
 as described.
 It throws an exception from parsing if a required option isn't present.

 This is my test case:
 {{{
 #include <boost/program_options.hpp>
 #include <string>
 #include <iostream>

 using namespace boost::program_options;
 using namespace std;

 int main(int argc, char *argv[])
 {
   options_description opts;
   opts.add_options()
     ("cfgfile,c", value<std::string>()->required(), "the configfile")
     ("fritz,f", value<std::string>()->default_value("/other/file"), "the
 output file")
    ;

    variables_map vm;
    try {
        store(parse_command_line(argc, argv, opts), vm);
        notify(vm);
    }
    catch (required_option& e) { // new exception type
        cout << "required option: " << e.what() << endl;
        return -1;
    }
    catch (...) {
        cout << "other exception: " << endl;
        return -1;
    }
 }

 }}}

 Does it make sense? Is it useful?

 I'm not a Boost maintainer, so I won't change the state of this ticket
 :-).

 Thanks

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2982#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC