13 std::string stripped = raw_input;
15 if(stripped[0] ==
'-') {
16 stripped.erase(stripped.begin() + 1, stripped.end());
19 if(stripped[0] ==
'-') {
20 stripped.erase(stripped.begin() + 1, stripped.end());
28 namespace Suboption_impl {
29 std::string
pull_short(
const po::option_description &single_boost_option) {
30 std::string possible_short;
31 possible_short = single_boost_option.canonical_display_name(po::command_line_style::allow_dash_for_short);
32 if(possible_short.size() > 2 || possible_short[0] !=
'-' || possible_short[1] ==
'-') {
36 return possible_short;
40 std::string
pull_long(
const po::option_description &single_boost_option) {
41 return single_boost_option.canonical_display_name(po::command_line_style::allow_long);
45 Suboption::Suboption(
const std::string &init_longname, std::string init_short, ARG_TYPE init_expected_types):
46 m_long(init_longname),
48 m_expected_arg(init_expected_types) {
54 m_long(Suboption_impl::
pull_long(init_boost_option)),
55 m_short(Suboption_impl::
pull_short(init_boost_option)),
56 m_expected_arg(
ArgHandler::determine_type(init_boost_option)) {
62 throw std::runtime_error(
"--long option must be at least 3 characters long and -s(hort) must be exactly 2!");
65 throw std::runtime_error(
"Suboption --long and -s(hort) tags must include leading '-' characters!");
78 if(test_tag.size() == 2) {
83 return (test_tag ==
m_long);
86 throw std::runtime_error(
"The impossible has occurred. Stepped through an if/else block and hit neither");
95 Option::Option(
const std::string &init_tag,
const std::vector<Suboption> &init_allowed_subopts):
97 m_avail_suboptions(init_allowed_subopts) {
100 Option::Option(
const std::string &init_tag,
const po::options_description &init_premade_descs):
104 for(
auto it = init_premade_descs.options().begin(); it != init_premade_descs.options().end(); ++it) {
119 std::vector<std::string> suboption_tag_list;
121 suboption_tag_list.push_back(it->long_tag());
124 return suboption_tag_list;
136 if(it->matches(suboption_tag)) {
137 return it->argument_type();
141 return ARG_TYPE::VOID;
145 return (test_tag ==
m_tag);
151 m_avail_options(init_options) {
160 std::vector<std::string> option_list;
162 option_list.push_back(it->tag());
176 if(it->matches(option_tag)) {
177 return it->probe_suboptions();
182 return std::vector<std::string>({
"BASH_COMP_PATH"});
192 std::vector<std::string> arguments;
196 switch(required_arg) {
205 case ARG_TYPE::COMMAND:
209 case ARG_TYPE::SCELNAME:
213 case ARG_TYPE::QUERY:
217 case ARG_TYPE::OPERATOR:
221 case ARG_TYPE::CONFIGNAME:
225 case ARG_TYPE::COORDTYPE:
234 if(!arguments.size()) {
235 arguments.push_back(
"BASH_COMP_PATH");
255 if(it->matches(option_tag)) {
256 return it->probe_argument_type(suboption_tag);
260 return ARG_TYPE::VOID;
static void operator_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for OPERATOR.
std::vector< std::string > probe_suboptions(const std::string &option_tag) const
For a particular option, get the available suboptions.
std::vector< Suboption > m_avail_suboptions
List of all the available –suboptions this option has.
ARG_TYPE probe_argument_type(const std::string &suboption_tag) const
For a particular –suboption, get what kind of arguments are expected. suboption_tag should be pre-st...
ArgHandler::ARG_TYPE ARG_TYPE
Option(const std::string &init_tag, const po::options_description &init_premade_descs)
Construct with program options.
bool matches(const std::string &test_tag) const
Check if the given string corresponds to the tag of *this.
const std::string m_long
–long identifier (includes leading "--")
std::string tag() const
Return the identifying name of *this (e.g. "super", "monte", etc)
const std::string m_short
-s(hort) identifyer (includes leading '-')
static void query_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for QUERY.
std::string short_tag() const
Return short name as char.
std::string strip_argument(const std::string &raw_input)
Remove "--" or "-" from beginning of string if it exists, and return as new string.
bool matches(const std::string &test_tag) const
See if a provided string matches either the –long or -s(hort) tags. Expects leading '-' characters...
std::string long_tag() const
Return long name in string format.
void _sanity_throw() const
Make sure values make sense.
std::string pull_long(const po::option_description &single_boost_option)
Get the –long tag from boost.
static void void_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for VOID (i.e. do nothing) ...
static void path_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for PATH.
ARG_TYPE argument_type() const
Return the expected types of arguments that follow *this.
const ARG_TYPE m_expected_arg
Type of arguments expected.
std::vector< std::string > probe_options() const
Construct by passing boost program options (eventually preferred so that it can update itself) ...
std::vector< std::string > probe_suboptions() const
Return what the suboptions (–long format) for *this are.
void push_back(const Option &new_option)
Guess what should be returned based on the current word (probably not gonna make it that smart) ...
Suboption(const std::string &init_longname, std::string init_short, ARG_TYPE init_expected_types)
Explicit construction. Be sure to include "--" and '-' in the tags.
std::string pull_short(const po::option_description &single_boost_option)
Get the -s(hort) tag from boost, or make it "- " if it doesn't exist.
std::string m_tag
Name that identifies this casm option (e.g. "monte", "init", etc)
static void command_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for COMMAND.
std::vector< std::string > probe_arguments(const std::string &option_tag, const std::string &suboption_tag) const
Return the arguments that should be bash completed.
std::vector< Option > m_avail_options
List of all the available (presumably casm) options (e.g. "monte", "init", etc)
Engine()
Default constructor so you can push back your own things.
ARG_TYPE _probe_argument_type(const std::string &option_tag, const std::string &suboption_tag) const
For a particular option with suboption, get what kind of arguments are expected.