client/Response: refactor FormatError() to use libfmt
This commit is contained in:
@@ -325,9 +325,9 @@ command_check_request(const struct command *cmd, Response &r,
|
||||
unsigned permission, Request args) noexcept
|
||||
{
|
||||
if (cmd->permission != (permission & cmd->permission)) {
|
||||
r.FormatError(ACK_ERROR_PERMISSION,
|
||||
"you don't have permission for \"%s\"",
|
||||
cmd->cmd);
|
||||
r.FmtError(ACK_ERROR_PERMISSION,
|
||||
FMT_STRING("you don't have permission for \"{}\""),
|
||||
cmd->cmd);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -338,17 +338,19 @@ command_check_request(const struct command *cmd, Response &r,
|
||||
return true;
|
||||
|
||||
if (min == max && unsigned(max) != args.size) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"wrong number of arguments for \"%s\"",
|
||||
cmd->cmd);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("wrong number of arguments for \"{}\""),
|
||||
cmd->cmd);
|
||||
return false;
|
||||
} else if (args.size < unsigned(min)) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"too few arguments for \"%s\"", cmd->cmd);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("too few arguments for \"{}\""),
|
||||
cmd->cmd);
|
||||
return false;
|
||||
} else if (max >= 0 && args.size > unsigned(max)) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"too many arguments for \"%s\"", cmd->cmd);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("too many arguments for \"{}\""),
|
||||
cmd->cmd);
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
@@ -360,8 +362,8 @@ command_checked_lookup(Response &r, unsigned permission,
|
||||
{
|
||||
const struct command *cmd = command_lookup(cmd_name);
|
||||
if (cmd == nullptr) {
|
||||
r.FormatError(ACK_ERROR_UNKNOWN,
|
||||
"unknown command \"%s\"", cmd_name);
|
||||
r.FmtError(ACK_ERROR_UNKNOWN,
|
||||
FMT_STRING("unknown command \"{}\""), cmd_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@@ -34,6 +34,8 @@
|
||||
#include "util/ASCII.hxx"
|
||||
#include "song/Filter.hxx"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -183,8 +185,8 @@ handle_count(Client &client, Request args, Response &r)
|
||||
const char *s = args[args.size - 1];
|
||||
group = tag_name_parse_i(s);
|
||||
if (group == TAG_NUM_OF_ITEM_TYPES) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"Unknown tag type: %s", s);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("Unknown tag type: {}"), s);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
@@ -252,8 +254,8 @@ handle_list(Client &client, Request args, Response &r)
|
||||
|
||||
const auto tagType = tag_name_parse_i(tag_name);
|
||||
if (tagType == TAG_NUM_OF_ITEM_TYPES) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"Unknown tag type: %s", tag_name);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("Unknown tag type: {}"), tag_name);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
@@ -266,9 +268,9 @@ handle_list(Client &client, Request args, Response &r)
|
||||
args.front()[0] != '(') {
|
||||
/* for compatibility with < 0.12.0 */
|
||||
if (tagType != TAG_ALBUM) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"should be \"%s\" for 3 arguments",
|
||||
tag_item_names[TAG_ALBUM]);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("should be \"{}\" for 3 arguments"),
|
||||
tag_item_names[TAG_ALBUM]);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
@@ -281,8 +283,8 @@ handle_list(Client &client, Request args, Response &r)
|
||||
const char *s = args[args.size - 1];
|
||||
const auto group = tag_name_parse_i(s);
|
||||
if (group == TAG_NUM_OF_ITEM_TYPES) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"Unknown tag type: %s", s);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("Unknown tag type: {}"), s);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
|
@@ -407,8 +407,9 @@ handle_idle(Client &client, Request args, Response &r)
|
||||
for (const char *i : args) {
|
||||
unsigned event = idle_parse_name(i);
|
||||
if (event == 0) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"Unrecognized idle event: %s", i);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("Unrecognized idle event: {}"),
|
||||
i);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,8 @@
|
||||
#include "queue/Playlist.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
CommandResult
|
||||
handle_addtagid(Client &client, Request args, Response &r)
|
||||
{
|
||||
@@ -33,7 +35,8 @@ handle_addtagid(Client &client, Request args, Response &r)
|
||||
const char *const tag_name = args[1];
|
||||
const TagType tag_type = tag_name_parse_i(tag_name);
|
||||
if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
||||
r.FormatError(ACK_ERROR_ARG, "Unknown tag type: %s", tag_name);
|
||||
r.FmtError(ACK_ERROR_ARG, FMT_STRING("Unknown tag type: {}"),
|
||||
tag_name);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
@@ -53,8 +56,9 @@ handle_cleartagid(Client &client, Request args, Response &r)
|
||||
const char *const tag_name = args[1];
|
||||
tag_type = tag_name_parse_i(tag_name);
|
||||
if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
||||
r.FormatError(ACK_ERROR_ARG,
|
||||
"Unknown tag type: %s", tag_name);
|
||||
r.FmtError(ACK_ERROR_ARG,
|
||||
FMT_STRING("Unknown tag type: {}"),
|
||||
tag_name);
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user