14 std::string stripped = raw_input;
16 if (stripped[0] ==
'-') {
17 stripped.erase(stripped.begin() + 1, stripped.end());
20 if (stripped[0] ==
'-') {
21 stripped.erase(stripped.begin() + 1, stripped.end());
29 namespace Suboption_impl {
30 std::string
pull_short(
const po::option_description &single_boost_option) {
31 std::string possible_short;
32 possible_short = single_boost_option.canonical_display_name(
33 po::command_line_style::allow_dash_for_short);
34 if (possible_short.size() > 2 || possible_short[0] !=
'-' ||
35 possible_short[1] ==
'-') {
38 return possible_short;
42 std::string
pull_long(
const po::option_description &single_boost_option) {
43 return single_boost_option.canonical_display_name(
44 po::command_line_style::allow_long);
50 : m_long(init_longname),
52 m_expected_arg(init_expected_types) {
57 : m_long(Suboption_impl::
pull_long(init_boost_option)),
58 m_short(Suboption_impl::
pull_short(init_boost_option)),
59 m_expected_arg(
ArgHandler::determine_type(init_boost_option)) {
65 throw std::runtime_error(
66 "--long option must be at least 3 characters long and -s(hort) must be "
70 throw std::runtime_error(
71 "Suboption --long and -s(hort) tags must include leading '-' "
81 if (test_tag.size() == 2) {
86 return (test_tag ==
m_long);
89 throw std::runtime_error(
90 "The impossible has occurred. Stepped through an if/else block and hit "
99 const std::vector<Suboption> &init_allowed_subopts)
100 : m_tag(init_tag), m_avail_suboptions(init_allowed_subopts) {}
103 const po::options_description &init_premade_descs)
107 for (
auto it = init_premade_descs.options().begin();
108 it != init_premade_descs.options().end(); ++it) {
121 std::vector<std::string> suboption_tag_list;
124 suboption_tag_list.push_back(it->long_tag());
127 return suboption_tag_list;
140 if (it->matches(suboption_tag)) {
141 return it->argument_type();
145 return ARG_TYPE::VOID;
149 return (test_tag ==
m_tag);
155 : m_avail_options(init_options) {}
163 std::vector<std::string> option_list;
165 option_list.push_back(it->tag());
179 const std::string &option_tag)
const {
181 if (it->matches(option_tag)) {
182 return it->probe_suboptions();
187 return std::vector<std::string>({
"BASH_COMP_PATH"});
198 const std::string &option_tag,
const std::string &suboption_tag)
const {
199 std::vector<std::string> arguments;
203 switch (required_arg) {
212 case ARG_TYPE::COMMAND:
216 case ARG_TYPE::SCELNAME:
221 case ARG_TYPE::QUERY:
225 case ARG_TYPE::OPERATOR:
229 case ARG_TYPE::CONFIGNAME:
233 case ARG_TYPE::COORDTYPE:
237 case ARG_TYPE::DBTYPE:
241 case ARG_TYPE::ENUMMETHOD:
245 case ARG_TYPE::CONFIGTYPE:
249 case ARG_TYPE::CALCTYPE:
269 case ARG_TYPE::PROPERTY:
273 case ARG_TYPE::INFOMETHOD:
282 if (!arguments.size()) {
283 arguments.push_back(
"BASH_COMP_PATH");
300 const std::string &suboption_tag)
const {
302 if (it->matches(option_tag)) {
303 return it->probe_argument_type(suboption_tag);
307 return ARG_TYPE::VOID;
static void ref_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for REF.
static void infomethod_to_bash(std::vector< std::string > &arguments)
static void void_to_bash(std::vector< std::string > &arguments)
static void configtype_to_bash(std::vector< std::string > &arguments)
static void eci_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for ECI.
static void calctype_to_bash(std::vector< std::string > &arguments)
static void operator_to_bash(std::vector< std::string > &arguments)
static void clex_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for CLEX.
static void property_to_bash(std::vector< std::string > &arguments)
static void command_to_bash(std::vector< std::string > &arguments)
static void scelname_to_bash(std::vector< std::string > &arguments)
static void dbtype_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for DBTYPE.
static void bset_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for BSET.
static void path_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for PATH.
static void enummethod_to_bash(std::vector< std::string > &arguments)
static void query_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for QUERY.
static void configname_to_bash(std::vector< std::string > &arguments)
Engine()
Default constructor so you can push back your own things.
std::vector< std::string > probe_options() const
Get a list of all available options.
std::vector< std::string > probe_suboptions(const std::string &option_tag) const
For a particular option, get the available suboptions.
ARG_TYPE _probe_argument_type(const std::string &option_tag, const std::string &suboption_tag) const
std::vector< Option > m_avail_options
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.
void push_back(const Option &new_option)
Append a new option to the engine.
Option(const std::string &init_tag, const po::options_description &init_premade_descs)
Construct with program options.
ARG_TYPE probe_argument_type(const std::string &suboption_tag) const
std::vector< Suboption > m_avail_suboptions
List of all the available –suboptions this option has.
std::string tag() const
Return the identifying name of *this (e.g. "super", "monte", etc)
std::string m_tag
Name that identifies this casm option (e.g. "monte", "init", etc)
bool matches(const std::string &test_tag) const
Check if the given string corresponds to the tag of *this.
std::vector< std::string > probe_suboptions() const
Return what the suboptions (–long format) for *this are.
std::string short_tag() const
Return short name as char.
ARG_TYPE argument_type() const
Return the expected types of arguments that follow *this.
const ARG_TYPE m_expected_arg
Type of arguments expected.
void _sanity_throw() const
Make sure values make sense.
const std::string m_long
–long identifier (includes leading "--")
const std::string m_short
-s(hort) identifyer (includes leading '-')
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.
bool matches(const std::string &test_tag) const
std::string long_tag() const
Return long name in string format.
std::string pull_long(const po::option_description &single_boost_option)
Get the –long tag from boost.
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.
ArgHandler::ARG_TYPE ARG_TYPE
std::string strip_argument(const std::string &raw_input)