boostorg / program_options

Boost.org program_options module
http://boost.org/libs/program_options
110 stars 107 forks source link

Supplying a list of possible values instead of a default value to an option? #115

Open IsabelMarleen opened 2 years ago

IsabelMarleen commented 2 years ago

Is there a way to specify a restricted list of values a command line option can take? I was thinking of something like this:

#include <boost/program_options.hpp>
namespace po = boost::program_options;

po::options_description description("General options");
description.add_options()
       ("key", po::value<string>()->possible_values("a", "b", "c"), "description of key");

Running executable --key d in the command line would throw an error but executable --key a would not. I know there is the option of manually processing the argument supplied to the key later on, but I was wondering if the functionality of identifying unambiguous abbreviations could be utilised.