mu-find: implement format=json2
Implement a new experimental json2 format for mu-find, which gets rid of the ":" prefixes for fields, i.e., "subject" instead of ":subject". Document it as well.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2008-2024 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -383,7 +383,10 @@ output_json(const Option<Message>& msg, const OutputInfo& info, const Options& o
|
||||
if (!msg)
|
||||
return Ok();
|
||||
|
||||
mu_println("{}{}", msg->sexp().to_json_string(), info.last ? "" : ",");
|
||||
const Sexp::Format frm{opts.find.format == Format::Json2 ? Sexp::Format::NoColon :
|
||||
Sexp::Format::Default};
|
||||
|
||||
mu_println("{}{}", msg->sexp().to_json_string(frm), info.last ? "" : ",");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
@ -443,6 +446,7 @@ get_output_func(const Options& opts)
|
||||
case Format::Sexp:
|
||||
return output_sexp;
|
||||
case Format::Json:
|
||||
case Format::Json2:
|
||||
return output_json;
|
||||
default:
|
||||
throw Error(Error::Code::Internal,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2022-2024 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -339,6 +339,9 @@ sub_find(CLI::App& sub, Options& opts)
|
||||
{ Format::Json,
|
||||
{"json", "JSON"}
|
||||
},
|
||||
{ Format::Json2,
|
||||
{"json2", "more idiomatic JSON"}
|
||||
},
|
||||
}};
|
||||
|
||||
sub.add_flag("--threads,-t", opts.find.threads,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -149,7 +149,7 @@ struct Options {
|
||||
std::string bookmark; /**< use bookmark */
|
||||
bool analyze; /**< analyze query */
|
||||
|
||||
enum struct Format { Plain, Links, Xml, Json, Sexp, Exec };
|
||||
enum struct Format { Plain, Links, Xml, Json, Json2, Sexp, Exec };
|
||||
Format format; /**< Output format */
|
||||
std::string exec; /**< cmd to execute on matches */
|
||||
bool skip_dups; /**< show only first with msg id */
|
||||
@ -256,7 +256,7 @@ struct Options {
|
||||
bool terminate; /**< add \f between msgs in view */
|
||||
OptSize summary_len; /**< max # of lines for summary */
|
||||
|
||||
enum struct Format { Plain, Sexp, Html };
|
||||
enum struct Format { Plain, Sexp, Html };
|
||||
Format format; /**< output format*/
|
||||
|
||||
StringVec files; /**< Message file(s) */
|
||||
|
||||
Reference in New Issue
Block a user