diff options
| -rw-r--r-- | docs/command-line-parsing.md | 2 | ||||
| -rw-r--r-- | src/compile/cli.c | 11 | ||||
| -rw-r--r-- | src/compile/cli.h | 2 | ||||
| -rw-r--r-- | src/tomo.c | 7 |
4 files changed, 14 insertions, 8 deletions
diff --git a/docs/command-line-parsing.md b/docs/command-line-parsing.md index 92e9a1c9..d0153e37 100644 --- a/docs/command-line-parsing.md +++ b/docs/command-line-parsing.md @@ -253,6 +253,8 @@ Supported metadata: is an argument parsing error. This should be a description of the program with a multi-line documentation of commonly used flags. +- `MANPAGE`: the full manpage (overrules the options below). + - `MANPAGE_SYNOPSYS`: the synopsis section of the manpage (inserted literally). - `MANPAGE_DESCRIPTION`: the description section of the manpage (inserted literally). diff --git a/src/compile/cli.c b/src/compile/cli.c index b92a5784..7cd3cc7c 100644 --- a/src/compile/cli.c +++ b/src/compile/cli.c @@ -187,14 +187,21 @@ Text_t compile_cli_arg_call(env_t *env, ast_t *ast, Text_t fn_name, type_t *fn_t } public -Text_t compile_manpage(Text_t program, OptionalText_t synopsis, OptionalText_t description, arg_t *args) { +Text_t compile_manpage(Text_t program, ast_t *ast, arg_t *args) { + OptionalText_t user_manpage = ast_metadata(ast, "MANPAGE"); + if (user_manpage.tag != TEXT_NONE) { + return user_manpage; + } + + OptionalText_t synopsys = ast_metadata(ast, "MANPAGE_SYNOPSYS"); + OptionalText_t description = ast_metadata(ast, "MANPAGE_DESCRIPTION"); Text_t date = Text(""); // TODO: use date Text_t man = Texts(".\\\" Automatically generated by Tomo\n" ".TH \"", Text$upper(program, Text("C")), "\" \"1\" \"", date, "\" \"\" \"\"\n" ".SH NAME\n", - program, " \\- ", synopsis.tag == TEXT_NONE ? Text("a Tomo program") : synopsis, "\n"); + program, " \\- ", synopsys.tag == TEXT_NONE ? Text("a Tomo program") : synopsys, "\n"); if (description.tag != TEXT_NONE) { man = Texts(man, ".SH DESCRIPTION\n", description, "\n"); diff --git a/src/compile/cli.h b/src/compile/cli.h index fbb7347b..907554a6 100644 --- a/src/compile/cli.h +++ b/src/compile/cli.h @@ -8,4 +8,4 @@ #include "../types.h" Text_t compile_cli_arg_call(env_t *env, ast_t *ast, Text_t fn_name, type_t *fn_type, const char *version); -Text_t compile_manpage(Text_t program, OptionalText_t synopsis, OptionalText_t description, arg_t *args); +Text_t compile_manpage(Text_t program, ast_t *ast, arg_t *args); @@ -877,12 +877,9 @@ Path_t compile_executable(env_t *base_env, Path_t path, Path_t exe_path, List_t Path_t manpage_file = build_file(Path$with_extension(path, Text(".1"), true), ""); if (clean_build || !Path$is_file(manpage_file, true) || is_stale(manpage_file, path, true)) { - OptionalText_t synopsys = ast_metadata(ast, "MANPAGE_SYNOPSYS"); - OptionalText_t description = ast_metadata(ast, "MANPAGE_DESCRIPTION"); - Text_t manpage = compile_manpage(Path$base_name(exe_path), synopsys, description, - Match(main_binding->type, FunctionType)->args); - if (!quiet) print("Wrote manpage:\t", Path$relative_to(manpage_file, Path$current_dir())); + Text_t manpage = compile_manpage(Path$base_name(exe_path), ast, Match(main_binding->type, FunctionType)->args); Path$write(manpage_file, manpage, 0644); + if (!quiet) print("Wrote manpage:\t", Path$relative_to(manpage_file, Path$current_dir())); } else { if (verbose) whisper("Unchanged: ", manpage_file); } |
