Migrate settings.cpp to function_ptr_command

This commit is contained in:
Ilari Liusvaara 2011-09-17 01:12:53 +03:00
parent 35d1875b44
commit d47eaa277b

View file

@ -11,12 +11,9 @@ namespace
{
std::map<std::string, setting*>* settings;
class set_command : public command
{
public:
set_command() throw(std::bad_alloc) : command("set-setting") {}
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
function_ptr_command set_setting("set-setting", "set a setting",
"Syntax: set-setting <setting> [<value>]\nSet setting to a new value. Omit <value> to set to ''\n",
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
std::string syntax = "Syntax: set-setting <setting> [<value>]";
tokensplitter t(args);
std::string settingname = t;
@ -26,21 +23,11 @@ namespace
setting::set(settingname, settingvalue);
window::out() << "Setting '" << settingname << "' set to '" << settingvalue << "'"
<< std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "set a setting"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: set-setting <setting> [<value>]\n"
"Set setting to a new value. Omit <value> to set to ''\n";
}
} set_setting;
});
class unset_command : public command
{
public:
unset_command() throw(std::bad_alloc) : command("unset-setting") {}
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
function_ptr_command unset_setting("unset-setting", "unset a setting",
"Syntax: unset-setting <setting>\nTry to unset a setting. Note that not all settings can be unset\n",
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
std::string syntax = "Syntax: unset-setting <setting>";
tokensplitter t(args);
std::string settingname = t;
@ -48,21 +35,11 @@ namespace
throw std::runtime_error("Expected setting name and nothing else");
setting::blank(settingname);
window::out() << "Setting '" << settingname << "' unset" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "unset a setting"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: unset-setting <setting>\n"
"Try to unset a setting. Note that not all settings can be unset\n";
}
} unset_setting;
});
class get_command : public command
{
public:
get_command() throw(std::bad_alloc) : command("get-setting") {}
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
function_ptr_command get_command("get-setting", "get value of a setting",
"Syntax: get-setting <setting>\nShow value of setting\n",
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
tokensplitter t(args);
std::string settingname = t;
if(settingname == "" || t.tail() != "")
@ -72,32 +49,15 @@ namespace
<< setting::get(settingname) << "'" << std::endl;
else
window::out() << "Setting '" << settingname << "' unset" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "get value of a setting"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: get-setting <setting>\n"
"Show value of setting\n";
}
} get_setting;
});
class shsettings_command : public command
{
public:
shsettings_command() throw(std::bad_alloc) : command("show-settings") {}
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
{
function_ptr_command show_settings("show-settings", "Show values of all settings",
"Syntax: show-settings\nShow value of all settings\n",
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
if(args != "")
throw std::runtime_error("This command does not take arguments");
setting::print_all();
}
std::string get_short_help() throw(std::bad_alloc) { return "Show value of all settings"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: show-settings\n"
"Show value of all settings\n";
}
} sh_setting;
});
}
setting::setting(const std::string& name) throw(std::bad_alloc)