commit 79d63177d7d0e2c18570eb4468ac23699df8a1c5
parent 45a74ae08187a0748b34217ce04c634bd48d3f79
Author: Alexey Yerin <yyp@disroot.org>
Date: Mon, 30 Aug 2021 22:06:23 +0300
cmd/haredoc: hide undocumented members unless -a is specified
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/cmd/haredoc/hare.ha b/cmd/haredoc/hare.ha
@@ -12,20 +12,24 @@ fn emit_hare(ctx: *context) (void | error) = {
const summary = ctx.summary;
// XXX: Should we emit the dependencies, too?
for (let i = 0z; i < len(summary.types); i += 1) {
- details_hare(summary.types[i])?;
+ details_hare(ctx, summary.types[i])?;
};
for (let i = 0z; i < len(summary.errors); i += 1) {
- details_hare(summary.errors[i])?;
+ details_hare(ctx, summary.errors[i])?;
};
for (let i = 0z; i < len(summary.globals); i += 1) {
- details_hare(summary.globals[i])?;
+ details_hare(ctx, summary.globals[i])?;
};
for (let i = 0z; i < len(summary.funcs); i += 1) {
- details_hare(summary.funcs[i])?;
+ details_hare(ctx, summary.funcs[i])?;
};
};
-fn details_hare(decl: ast::decl) (void | error) = {
+fn details_hare(ctx: *context, decl: ast::decl) (void | error) = {
+ if (len(decl.docs) == 0 && !ctx.show_undocumented) {
+ return;
+ };
+
const iter = strings::tokenize(decl.docs, "\n");
for (true) match (strings::next_token(&iter)) {
s: str => if (len(s) != 0) {
diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha
@@ -26,16 +26,19 @@ type context = struct {
summary: summary,
format: format,
template: bool,
+ show_undocumented: bool,
readme: nullable *io::stream,
};
export fn main() void = {
let fmt = if (tty::isatty(os::stdout)) format::TTY else format::HARE;
let template = true;
+ let show_undocumented = false;
const help: [_]getopt::help = [
"reads and formats Hare documentation",
('F', "format", "specify output format (hare, tty, html, or gemtext)"),
('t', "disable HTML template (requries postprocessing)"),
+ ('a', "show undocumented members (only applies to -Fhare and -Ftty)"),
"[identifiers...]",
];
const cmd = getopt::parse(os::args, help...);
@@ -51,10 +54,16 @@ export fn main() void = {
else if (opt.1 == "gemtext") format::GEMTEXT
else fmt::fatal("Invalid format {}", opt.1),
't' => template = false,
+ 'a' => show_undocumented = true,
* => abort(),
};
};
+ if (show_undocumented) switch (fmt) {
+ format::HARE, format::TTY => void,
+ * => fmt::fatal("Option -a must be used only with -Fhare or -Ftty"),
+ };
+
let decls: []ast::decl = [];
defer free(decls); // TODO: Free interior state
@@ -110,6 +119,7 @@ export fn main() void = {
format = fmt,
template = template,
readme = readme,
+ show_undocumented = show_undocumented,
};
match (emit(&ctx)) {
void => void,
diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha
@@ -12,20 +12,24 @@ fn emit_tty(ctx: *context) (void | error) = {
const summary = ctx.summary;
// XXX: Should we emit the dependencies, too?
for (let i = 0z; i < len(summary.types); i += 1) {
- details_tty(summary.types[i])?;
+ details_tty(ctx, summary.types[i])?;
};
for (let i = 0z; i < len(summary.errors); i += 1) {
- details_tty(summary.errors[i])?;
+ details_tty(ctx, summary.errors[i])?;
};
for (let i = 0z; i < len(summary.globals); i += 1) {
- details_tty(summary.globals[i])?;
+ details_tty(ctx, summary.globals[i])?;
};
for (let i = 0z; i < len(summary.funcs); i += 1) {
- details_tty(summary.funcs[i])?;
+ details_tty(ctx, summary.funcs[i])?;
};
};
-fn details_tty(decl: ast::decl) (void | error) = {
+fn details_tty(ctx: *context, decl: ast::decl) (void | error) = {
+ if (len(decl.docs) == 0 && !ctx.show_undocumented) {
+ return;
+ };
+
const iter = strings::tokenize(decl.docs, "\n");
for (true) match (strings::next_token(&iter)) {
s: str => if (len(s) != 0) {