mirror of https://github.com/djcb/mu.git
Useful information for devising queries. Directly generated from the source. Add manpages, too.pull/2234/merge
parent
30e7b5d9ec
commit
8f9d1e5e60
@ -0,0 +1,32 @@ |
||||
.TH MU FIELDS 1 "April 2022" "User Manuals" |
||||
|
||||
.SH NAME |
||||
|
||||
mu fields\- list all message fields |
||||
|
||||
.SH SYNOPSIS |
||||
|
||||
.B mu fields [options] |
||||
|
||||
.SH DESCRIPTION |
||||
|
||||
\fBmu fields\fR is the \fBmu\fR command for showing a table of message fields |
||||
and their properties. |
||||
|
||||
.SH OPTIONS |
||||
|
||||
Inherits common options from |
||||
.BR mu(1) |
||||
|
||||
.SH BUGS |
||||
|
||||
Please report bugs if you find them: |
||||
.BR https://github.com/djcb/mu/issues |
||||
|
||||
.SH AUTHOR |
||||
|
||||
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> |
||||
|
||||
.SH "SEE ALSO" |
||||
|
||||
.BR mu (1) |
@ -0,0 +1,31 @@ |
||||
.TH MU FLAGS 1 "April 2022" "User Manuals" |
||||
|
||||
.SH NAME |
||||
|
||||
mu flags\- list all message flags |
||||
|
||||
.SH SYNOPSIS |
||||
|
||||
.B mu flags [options] |
||||
|
||||
.SH DESCRIPTION |
||||
|
||||
\fBmu flags\fR is the \fBmu\fR command for showing a table of message flags and their properties, which is useful for devising queries. |
||||
|
||||
.SH OPTIONS |
||||
|
||||
Inherits common options from |
||||
.BR mu(1) |
||||
|
||||
.SH BUGS |
||||
|
||||
Please report bugs if you find them: |
||||
.BR https://github.com/djcb/mu/issues |
||||
|
||||
.SH AUTHOR |
||||
|
||||
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> |
||||
|
||||
.SH "SEE ALSO" |
||||
|
||||
.BR mu (1) |
@ -0,0 +1,131 @@ |
||||
/*
|
||||
** Copyright (C) 2022 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 Free Software |
||||
** Foundation; either version 3, or (at your option) any later version. |
||||
** |
||||
** This program is distributed in the hope that it will be useful, but WITHOUT |
||||
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||||
** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
||||
** details. |
||||
** |
||||
** You should have received a copy of the GNU General Public License along with |
||||
** this program; if not, write to the Free Software Foundation, Inc., 51 |
||||
** Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
** |
||||
*/ |
||||
|
||||
#include "mu-cmd.hh" |
||||
#include <message/mu-message.hh> |
||||
#include <iostream> |
||||
#include "mu-flags.hh" |
||||
#include "utils/mu-utils.hh" |
||||
#include "thirdparty/tabulate.hpp" |
||||
|
||||
using namespace Mu; |
||||
|
||||
static void |
||||
show_fields(const MuConfig* opts) |
||||
{ |
||||
using namespace tabulate; |
||||
using namespace std::string_literals; |
||||
|
||||
Table fields; |
||||
fields.add_row({"field-name", "alias", "short", "search", |
||||
"value", "example", "description"}); |
||||
|
||||
if (!opts->nocolor) { |
||||
(*fields.begin()).format() |
||||
.font_style({FontStyle::bold}) |
||||
.font_color({Color::blue}); |
||||
} |
||||
|
||||
auto disp= [&](std::string_view sv)->std::string { |
||||
if (sv.empty()) |
||||
return ""; |
||||
else |
||||
return format("%*s", STR_V(sv)); |
||||
}; |
||||
|
||||
auto searchable=[&](const Field& field)->std::string { |
||||
if (field.is_boolean_term()) |
||||
return "boolean"; |
||||
if (field.is_indexable_term()) |
||||
return "index"; |
||||
if (field.is_normal_term()) |
||||
return "yes"; |
||||
if (field.is_contact()) |
||||
return "contact"; |
||||
if (field.is_range()) |
||||
return "range"; |
||||
return "no"; |
||||
}; |
||||
|
||||
size_t row{}; |
||||
field_for_each([&](auto&& field){ |
||||
if (field.is_internal()) |
||||
return; // skip.
|
||||
|
||||
fields.add_row({format("%*s", STR_V(field.name)), |
||||
field.alias.empty() ? "" : format("%*s", STR_V(field.alias)), |
||||
field.shortcut ? format("%c", field.shortcut) : ""s, |
||||
searchable(field), |
||||
field.is_value() ? "yes" : "no", |
||||
disp(field.example_query), |
||||
disp(field.description)}); |
||||
++row; |
||||
}); |
||||
|
||||
std::cout << fields << '\n'; |
||||
} |
||||
|
||||
static void |
||||
show_flags(const MuConfig* opts) |
||||
{ |
||||
using namespace tabulate; |
||||
using namespace std::string_literals; |
||||
|
||||
Table flags; |
||||
flags.add_row({"flag", "shortcut", "category", "description"}); |
||||
|
||||
if (!opts->nocolor) { |
||||
(*flags.begin()).format() |
||||
.font_style({FontStyle::bold}) |
||||
.font_color({Color::green}); |
||||
} |
||||
|
||||
flag_infos_for_each([&](const MessageFlagInfo& info) { |
||||
|
||||
flags.add_row({format("%*s", STR_V(info.name)), |
||||
format("%c", info.shortcut), |
||||
"<cat>"s, |
||||
std::string{info.description}}); |
||||
}); |
||||
|
||||
std::cout << flags << '\n'; |
||||
} |
||||
|
||||
|
||||
|
||||
Result<void> |
||||
Mu::mu_cmd_fields(const MuConfig* opts) |
||||
{ |
||||
g_return_val_if_fail(opts, Err(Error::Code::Internal, "no opts")); |
||||
|
||||
show_fields(opts); |
||||
|
||||
return Ok(); |
||||
|
||||
} |
||||
|
||||
Result<void> |
||||
Mu::mu_cmd_flags(const MuConfig* opts) |
||||
{ |
||||
g_return_val_if_fail(opts, Err(Error::Code::Internal, "no opts")); |
||||
|
||||
show_flags(opts); |
||||
|
||||
return Ok(); |
||||
|
||||
} |
Loading…
Reference in new issue