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

Open
#115 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
cli

Research direction

Start by tracing how boost/program_options handles po::value() and command-line value validation, then inspect where unambiguous option abbreviations are implemented. The work is done when an option can declare the values "a", "b", and "c", reject "d", accept valid values, and retain the relevant abbreviation behavior.

Written by the indexing model from the issue text.

Description

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.

Dominant language
C++
Stars
136
Forks
117
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/program_options

All issues in boostorg/program_options

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.