Skip to content

Interactive command line prompts with C++

License

Notifications You must be signed in to change notification settings

MrSimsure/cpp-inquirer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Inquirer

A single header C++11 library for interactive command line prompts.

Use

Simply include the header:

#include "inquirer.h"

And initialise the inquirer object (with optional title):

auto inquirer = alx::Inquirer("cpp-inquirer example");

To get the answers back, call inquirer.answer("some key"); with the key of your question. You will get a std::string as a value, so you will need to convert it to an approapriate type yourself.

Propmts

Text

inquirer.add_question({ "query", "What do you want to do?" });

Yes/No

inquirer.add_question({ "birthday", "Is this for a birthday?", alx::Type::yesNo });

Integer or decimal

inquirer.add_question({ "candles", "How many candles do you want?", alx::Type::integer });
// Or
inquirer.add_question({ "candles", "How many candles do you want?", alx::Type::decimal });

Select

inquirer.add_question({ "type", "What kind of a cake would you like?",
		        std::vector<std::string>{ "Chocolate", "Ice-cream", "Cheesecake", "Red velvet" }});

Confirm

inquirer.add_question({ "delivery", "Is this for delivery?", alx::Type::confirm });

Regex validated input

inquirer.add_question({ "number", "Enter your contact details:", "\\d{9}" });

Contributing

I'm more than happy to accept pull requests with some minor requirements:

  • Prefix your commit messages with a relevant change type. If the commit relates to a GitHub issue, include the issue number in the message. Example:

Types: added a new question type 'yes/no'

This addresses issue #123

or

Answers: added a way to return an answer with the correct type

  • Please follow the naming convention already established in the code. There is no clangformat, but I'm sure you can deduce it yourself.

About

Interactive command line prompts with C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 96.4%
  • CMake 2.8%
  • Shell 0.8%