1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 19:03:04 +00:00

utils/remote: add option to dump RPC response as JSON (#3819)

Co-authored-by: LaserEyess <LaserEyess@users.noreply.github.com>
This commit is contained in:
LaserEyess 2022-09-14 20:20:40 -04:00 committed by GitHub
parent 161330ae16
commit fe9aba702e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -87,6 +87,7 @@ struct Config
std::string unix_socket_path;
bool debug = false;
bool json = false;
bool use_ssl = false;
};
@ -234,7 +235,7 @@ enum
****
***/
static auto constexpr Options = std::array<tr_option, 97>{
static auto constexpr Options = std::array<tr_option, 98>{
{ { 'a', "add", "Add torrent files by filename or URL", "a", false, nullptr },
{ 970, "alt-speed", "Use the alternate Limits", "as", false, nullptr },
{ 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, nullptr },
@ -274,6 +275,7 @@ static auto constexpr Options = std::array<tr_option, 97>{
{ 941, "info-peers", "List the current torrent(s)' peers", "ip", false, nullptr },
{ 942, "info-pieces", "List the current torrent(s)' pieces", "ic", false, nullptr },
{ 943, "info-trackers", "List the current torrent(s)' trackers", "it", false, nullptr },
{ 'j', "json", "Return RPC response as a JSON string", "j", false, nullptr },
{ 920, "session-info", "Show the session's details", "si", false, nullptr },
{ 921, "session-stats", "Show the session's statistics", "st", false, nullptr },
{ 'l', "list", "List all torrents", "l", false, nullptr },
@ -415,6 +417,7 @@ static int getOptMode(int val)
case 'b': /* debug */
case 'n': /* auth */
case 968: /* Unix domain socket */
case 'j': /* JSON */
case 810: /* authenv */
case 'N': /* netrc */
case 820: /* UseSSL */
@ -2141,6 +2144,12 @@ static int processResponse(char const* rpcurl, std::string_view response, Config
TR_PRIsv_ARG(response));
}
if (config.json)
{
printf("%" TR_PRIsv, TR_PRIsv_ARG(response));
return status;
}
if (!tr_variantFromBuf(&top, TR_VARIANT_PARSE_JSON | TR_VARIANT_PARSE_INPLACE, response))
{
tr_logAddWarn(fmt::format("Unable to parse response '{}'", response));
@ -2457,6 +2466,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv, Co
config.debug = true;
break;
case 'j': /* return output as JSON */
config.json = true;
break;
case 968: /* Unix domain socket */
config.unix_socket_path = optarg;
break;

View file

@ -37,6 +37,7 @@ and
.Op Fl if
.Op Fl ip
.Op Fl it
.Op Fl j
.Op Fl l
.Op Fl m | M
.Op Fl n Ar user:pass
@ -187,6 +188,8 @@ List the specified torrent's peers
List the specified torrent's pieces
.It Fl it Fl -info-trackers
List the specified torrent's trackers
.It Fl j Fl -json
Return the RPC response as JSON
.It Fl si Fl -session-info
List session information from the server
.It Fl st Fl -session-stats