author | Olivier Brunel
<jjk@jjacky.com> 2023-04-18 11:12:57 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-04-19 07:17:27 UTC |
parent | 45cd0add924c7105adc80cf71c1192875d9f9cd5 |
src/include/ssp.h | +1 | -1 |
src/ssp/list.c | +9 | -3 |
src/ssp/show.c | +12 | -6 |
diff --git a/src/include/ssp.h b/src/include/ssp.h index 3359b00..c0f77d6 100644 --- a/src/include/ssp.h +++ b/src/include/ssp.h @@ -80,6 +80,6 @@ int open_db(struct ssp *ctx); /* show.c */ void show_site(unsigned options, struct ssp *ctx); -void show_site_ini(struct ssp *ctx); +void show_site_ini(unsigned options, struct ssp *ctx); #endif /* SSP_SSP_H */ diff --git a/src/ssp/list.c b/src/ssp/list.c index 14f7be4..a286450 100644 --- a/src/ssp/list.c +++ b/src/ssp/list.c @@ -12,7 +12,8 @@ enum { OPT_DETAILS = 1 << 0, OPT_SECRET = 1 << 1, /* must be the same as in show */ - OPT_FMT_INI = 1 << 2, + OPT_NO_COMMENTS = 1 << 2, /* must be the same as in show */ + OPT_FMT_INI = 1 << 3, }; struct list { @@ -23,6 +24,7 @@ struct list { COMMAND(list, "List all sites in the database", "[OPTION..] [<pattern>]", +" -C, --no-comments Do not show comments with --details/--format\n" " -d, --details Show sites' details\n" " -f, --format Output in INI-like format\n" " -S, --secret Show sites' secrets (implies --details)\n" @@ -33,6 +35,7 @@ static int parse_cmdline(int argc, const char *argv[], const char usage[], struct list *ctx) { const struct option options[] = { + OPTION_ARG_NONE('C', "no-comments", 0, OPTID_SHORTOPT), OPTION_ARG_NONE('d', "details", 0, OPTID_SHORTOPT), OPTION_ARG_NONE('f', "format", 0, OPTID_SHORTOPT), OPTION_ARG_NONE('S', "secret", 0, OPTID_SHORTOPT), @@ -43,6 +46,9 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct list *ctx int c; while ((c = parseopt(argc, argv, options, 0, &po))) switch (c) { + case 'C': + ctx->options |= OPT_NO_COMMENTS; + break; case 'd': ctx->options |= OPT_DETAILS; break; @@ -92,9 +98,9 @@ list_main(int argc, const char *argv[], const char *env[], const char usage[], v if (list.ptrn && fnmatch(list.ptrn, db_site(ctx), 0)) continue; if (list.options & OPT_FMT_INI) { - show_site_ini(ctx); + show_site_ini(list.options & OPT_NO_COMMENTS, ctx); } else if (list.options & OPT_DETAILS) { - show_site(list.options & OPT_SECRET, ctx); + show_site(list.options & (OPT_NO_COMMENTS | OPT_SECRET), ctx); } else { if (i) add(list.sep); add(ESC, db_site(ctx), ESC); diff --git a/src/ssp/show.c b/src/ssp/show.c index 80fbdcf..5f471b3 100644 --- a/src/ssp/show.c +++ b/src/ssp/show.c @@ -11,8 +11,9 @@ #include "ssp.h" enum { - OPT_SECRET = 1 << 1, /* must be the same as in list */ - OPT_FMT_INI = 1 << 2, + OPT_SECRET = 1 << 1, /* must be the same in list */ + OPT_NO_COMMENTS = 1 << 2, /* must be the same in list */ + OPT_FMT_INI = 1 << 3, }; struct show { @@ -21,6 +22,7 @@ struct show { COMMAND(show, "Show details of a site", "[OPTION..] <site>", +" -C, --no-comments Do not show site's comments\n" " -f, --format Output in INI-like format\n" " -S, --secret Show site's secret\n" ); @@ -29,6 +31,7 @@ static int parse_cmdline(int argc, const char *argv[], const char usage[], struct show *ctx) { const struct option options[] = { + OPTION_ARG_NONE('C', "no-comments", 0, OPTID_SHORTOPT), OPTION_ARG_NONE('f', "format", 0, OPTID_SHORTOPT), OPTION_ARG_NONE('S', "secret", 0, OPTID_SHORTOPT), OPTION_DONE @@ -37,6 +40,9 @@ parse_cmdline(int argc, const char *argv[], const char usage[], struct show *ctx int c; while ((c = parseopt(argc, argv, options, 0, &po))) switch (c) { + case 'C': + ctx->options |= OPT_NO_COMMENTS; + break; case 'f': ctx->options |= OPT_FMT_INI; break; @@ -71,7 +77,7 @@ show_site(unsigned options, struct ssp *ctx) buf[l] = 0; out(" Secret: ", buf); } - if (otp->data[otp->slen]) { + if (!(options & OPT_NO_COMMENTS) && otp->data[otp->slen]) { const char *s = otp->data + otp->slen; size_t l = strlen(s); out(" Comments:", (byte_chr(s, l, '\n') < l) ? "\n" : " ", s); @@ -79,7 +85,7 @@ show_site(unsigned options, struct ssp *ctx) } void -show_site_ini(struct ssp *ctx) +show_site_ini(unsigned options, struct ssp *ctx) { const struct otp *otp = db_otp(ctx); @@ -96,7 +102,7 @@ show_site_ini(struct ssp *ctx) base32_fmt(buf, otp->data, otp->slen, 0); buf[l] = 0; out("secret=", buf); - if (otp->data[otp->slen]) + if (!(options & OPT_NO_COMMENTS) && otp->data[otp->slen]) out("comments=", ESC, otp->data + otp->slen, ESC); } @@ -134,7 +140,7 @@ show_main(int argc, const char *argv[], const char *env[], const char usage[], v if (!r) out("no site ", ESC, site, ESC, " in database"); else if (show.options & OPT_FMT_INI) - show_site_ini(ctx); + show_site_ini(show.options & OPT_NO_COMMENTS, ctx); else show_site(show.options, ctx);