diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-18 17:12:20 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-18 17:12:20 -0400 |
| commit | 383a942bb3fe05be887a6622ca5ed86e9bba0662 (patch) | |
| tree | 381ca712bbbeb36308fb2866c3b4c516626b1abf /src/compile/cli.c | |
| parent | 48aa524e8c5aab6632c680971a8a31c542121993 (diff) | |
Added automatic manpages.
Diffstat (limited to 'src/compile/cli.c')
| -rw-r--r-- | src/compile/cli.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/compile/cli.c b/src/compile/cli.c index 820f0e2e..3337e250 100644 --- a/src/compile/cli.c +++ b/src/compile/cli.c @@ -1,5 +1,6 @@ // This file defines how to compile CLI argument parsing +#include "../stdlib/cli.h" #include "../environment.h" #include "../stdlib/datatypes.h" #include "../stdlib/optionals.h" @@ -131,3 +132,37 @@ Text_t compile_cli_arg_call(env_t *env, Text_t fn_name, type_t *fn_type, const c code = Texts(code, ");\n"); return code; } + +public +Text_t compile_manpage(Text_t program, OptionalText_t synopsis, OptionalText_t description, arg_t *args) { + 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"); + + if (description.tag != TEXT_NONE) { + man = Texts(man, ".SH DESCRIPTION\n", description, "\n"); + } + + man = Texts(man, ".SH OPTIONS\n"); + for (arg_t *arg = args; arg; arg = arg->next) { + man = Texts(man, "\n.TP\n\\f[B]\\-\\-", Text$from_str(arg->name), "\\f[R]"); + if (arg->alias) man = Texts(man, ", \\f[B]\\-", Text$from_str(arg->alias), "\\f[R]"); + if (arg->type->tag == BoolType) { + man = Texts(man, "\n.TP\n\\f[B]\\-\\-no\\-", Text$from_str(arg->name)); + } else if (is_numeric_type(arg->type)) { + man = Texts(man, " \\f[I]N\\f[R]"); + } else if (arg->type->tag == ListType) { + man = Texts(man, " \\f[I]value1\\f[R] \\f[I]value2...\\f[R]"); + } else if (arg->type->tag == TableType) { + man = Texts(man, " \\f[I]key1:value1\\f[R] \\f[I]key2:value2...\\f[R]"); + } else { + man = Texts(man, " \\f[I]value\\f[R]"); + } + } + + return man; +} |
