mirror of
https://github.com/merbanan/rtl_433.git
synced 2026-08-01 11:08:51 -04:00
Add protocols help listing as json (#3609)
This commit is contained in:
committed by
GitHub
parent
f0c2b6fe12
commit
e8b2a519a7
@@ -170,15 +170,12 @@ static void usage(int exit_code)
|
||||
_Noreturn
|
||||
static void help_protocols(r_device *devices, unsigned num_devices, int exit_code)
|
||||
{
|
||||
unsigned i;
|
||||
char disabledc;
|
||||
|
||||
if (devices) {
|
||||
FILE *fp = exit_code ? stderr : stdout;
|
||||
term_help_fprintf(fp,
|
||||
"\t\t= Supported device protocols =\n");
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
disabledc = devices[i].disabled ? '*' : ' ';
|
||||
for (unsigned i = 0; i < num_devices; i++) {
|
||||
char disabledc = devices[i].disabled ? '*' : ' ';
|
||||
if (devices[i].disabled <= 2) { // if not hidden
|
||||
fprintf(fp, " [%02u]%c %s\n", i + 1, disabledc, devices[i].name);
|
||||
}
|
||||
@@ -188,6 +185,20 @@ static void help_protocols(r_device *devices, unsigned num_devices, int exit_cod
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
_Noreturn static void help_protocols_json(r_device *devices, unsigned num_devices, int exit_code)
|
||||
{
|
||||
if (devices) {
|
||||
FILE *fp = exit_code ? stderr : stdout;
|
||||
fprintf(fp, "[");
|
||||
for (unsigned i = 0; i < num_devices; i++) {
|
||||
if (devices[i].disabled <= 2) { // if not hidden
|
||||
fprintf(fp, "{\"num\":%u,\"dis\":%u,\"desc\":\"%s\"}%s\n", i + 1, devices[i].disabled, devices[i].name, i + 1 < num_devices ? "," : "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(exit_code);
|
||||
}
|
||||
|
||||
_Noreturn
|
||||
static void help_device_selection(void)
|
||||
{
|
||||
@@ -793,6 +804,11 @@ static void parse_conf_option(r_cfg_t *cfg, int opt, char *arg)
|
||||
help_protocols(cfg->devices, cfg->num_r_devices, 0);
|
||||
}
|
||||
|
||||
// use arg of 'json' for machine-readable info
|
||||
if (!strcasecmp(arg, "json")) {
|
||||
help_protocols_json(cfg->devices, cfg->num_r_devices, 0);
|
||||
}
|
||||
|
||||
// use arg of 'v', 'vv', 'vvv' as global device verbosity
|
||||
if (*arg == 'v') {
|
||||
int decoder_verbosity = 0;
|
||||
|
||||
Reference in New Issue
Block a user