61 if (n <
args.size()) {
71 if (n <
args.size()) {
89 size_t first_space =
str_.find_first_of(
' ',
args.back());
90 size_t next_arg_begin =
str_.find_first_not_of(
' ', first_space);
91 if (next_arg_begin != std::string::npos) {
92 args.push_back(next_arg_begin);
100 mutable std::vector<size_t>
args;
117 template <
class Worker>
130 : handler(h), help(help), usage(usage), flags(flags)
135 return flags.find(f) != flags.npos;
165 for (
int i = 0;
i < 100; ++
i) {
172 cmd = actual_cmd + (data.empty() ?
"" :
" ") + data;
181 (
static_cast<Worker*
>(
this)->*(
c->handler))();
184 print(
get_cmd(),
_(
"This command is currently unavailable."));
189 symbols[
"command"] =
get_cmd();
191 print(
"help",
VGETTEXT(
"Unknown command '$command', try $help_command "
192 "for a list of available commands.", symbols));
198 std::vector<std::string>
res;
200 res.push_back(
i.first);
213 _(
"Available commands list and command-specific help. "
214 "Use \"help all\" to include currently unavailable commands."),
215 _(
"do not translate the 'all'^[all|<command>]"));
259 symbols[
"arg_id"] = std::to_string(argn);
274 typename command_map::const_iterator
i =
command_map_.find(cmd);
288 std::stringstream ss;
298 if (!
i.second.flags.empty()) {
299 ss <<
" (" <<
i.second.flags <<
") ";
306 symbols[
"list_of_commands"] = ss.str();
308 print(
_(
"help"),
VGETTEXT(
"Available commands $flags_description:\n$list_of_commands", symbols));
309 print(
_(
"help"),
VGETTEXT(
"Type $help_command <command> for more info.", symbols));
317 std::stringstream ss;
319 if (c->help.empty() && c->usage.empty()) {
320 ss <<
_(
" No help available.");
323 ss <<
" - " << c->help;
325 if (!c->usage.empty()) {
326 ss <<
" " <<
_(
"Usage:") <<
" " <<
cmd_prefix_ << cmd <<
" " << c->usage;
331 ss <<
" (" <<
_(
"aliases:") <<
" " <<
utils::join(l,
" ") <<
")";
333 print(
_(
"help"), ss.str());
354 std::pair<typename command_map::iterator, bool>
r;
355 r =
command_map_.insert(
typename command_map::value_type(cmd, c));
374 std::vector<std::string> aliases;
375 typedef command_alias_map::value_type
p;
377 if (
i.second == cmd) {
378 aliases.push_back(
i.first);
392 template <
class Worker>
395 template <
class Worker>
398 template <
class Worker>
401 template <
class Worker>
404 template <
class Worker>
void command_failed(const std::string &message, bool=false)
static bool help_on_unknown_
virtual std::string get_command_flags_description(const command &) const
void parse(const std::string &str)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
void advance_to_arg(unsigned n) const
void(Worker::* command_handler)()
static bool show_unavailable_
cmd_arg_parser & operator=(const cmd_arg_parser &)
std::string get_cmd() const
command(command_handler h, const std::string help="", const std::string &usage="", const std::string flags="")
static command_map command_map_
virtual void init_map()=0
virtual bool is_enabled(const command &) const
virtual void assert_existence(const std::string &cmd)
GLsizeiptr const GLvoid GLenum usage
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definitions for the interface to Wesnoth Markup Language (WML).
std::vector< std::string > get_commands_list() const
cmd_arg_parser(const std::string &str)
std::string & strip(std::string &str)
Remove whitespace from the front and back of the string 'str'.
static UNUSEDNOWARN std::string _(const char *str)
void dispatch(std::string cmd)
std::map< std::string, t_string > string_map
virtual void register_alias(const std::string &to_cmd, const std::string &cmd)
std::string get_data(unsigned n) const
bool has_flag(const char f) const
GLsizei const GLfloat * value
cl_event GLbitfield flags
std::string get_arg(unsigned n) const
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
command & add_flag(const char f)
static std::string cmd_prefix_
std::map< std::string, std::string > command_alias_map
std::map< std::string, command > command_map
command * get_command(const std::string &cmd)
static void set_cmd_prefix(std::string value)
GLfloat GLfloat GLfloat GLfloat h
virtual std::string get_arg(unsigned argn) const
static const std::vector< std::string > get_aliases(const std::string &cmd)
GLdouble GLdouble GLdouble r
virtual std::string get_cmd() const
const command * get_command(const std::string &cmd) const
Handling of system events.
static void set_help_on_unknown(bool value)
std::vector< size_t > args
GLsizei GLenum GLuint GLuint GLsizei char * message
virtual std::string get_data(unsigned argn=1) const
static command_alias_map command_alias_map_
bool help_command(const std::string &acmd)
virtual void parse_cmd(const std::string &cmd_string)
virtual void register_command(const std::string &cmd, command_handler h, const std::string &help="", const std::string &usage="", const std::string &flags="")
virtual std::string get_flags_description() const
GLsizei const GLcharARB ** string
const std::string & get_str() const
virtual void print(const std::string &title, const std::string &message)=0
virtual ~map_command_handler()
std::string get_actual_cmd(const std::string &cmd) const
void command_failed_need_arg(int argn)