From 5e99a791e62d77e99b3e313947b8c1f00587a7e6 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 4 Dec 2020 17:29:31 +0100 Subject: [PATCH 1/7] Create cmd to generate man pages for prof commands `profanity mangen` will create for each command (`/account`, `/roster`) an own manpage (`profanity-account.1`, `profanity-roster.1`) See https://github.com/profanity-im/profanity/issues/1444 Needs some polishing formatting wise. --- RELEASE_GUIDE.md | 4 +++ src/command/cmd_defs.c | 67 ++++++++++++++++++++++++++++++++++++++++++ src/command/cmd_defs.h | 1 + src/main.c | 11 +++++-- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/RELEASE_GUIDE.md b/RELEASE_GUIDE.md index 2871d0f2..719a5969 100644 --- a/RELEASE_GUIDE.md +++ b/RELEASE_GUIDE.md @@ -15,6 +15,10 @@ Usually release candidates are tagged 0.6.0.rc1, 0.6.0.rc2 and tested for a week * Generate HTML docs (the docgen argument only works when package status is development) `./profanity docgen` +* Generate manpages for profanity commands (the mangen argument only works when package status is development) + `./profanity mangen` + These files should be added to the docs subfolder and added to git whenever a command changes. + * Determine if libprofanitys version needs to be [increased](https://github.com/profanity-im/profanity/issues/973) * Update plugin API docs (./apidocs/c and ./apidocs/python) need to run the `gen.sh` and commit the results to the website git repo * Update CHANGELOG diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 53c42bae..e12fdb8a 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2833,3 +2833,70 @@ command_docgen(void) printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); g_list_free(cmds); } + +void +command_mangen(void) +{ + GList* cmds = NULL; + + for (unsigned int i = 0; i < ARRAY_SIZE(command_defs); i++) { + Command* pcmd = command_defs + i; + cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command); + } + + mkdir_recursive("docs"); + + GList* curr = cmds; + while (curr) { + Command* pcmd = curr->data; + + char* filename = NULL; + if (asprintf(&filename, "docs/profanity-%s.1", &pcmd->cmd[1]) == -1) { + // TODO: error + return; + } + FILE* manpage = fopen(filename, "w"); + free(filename); + + fputs(".TH man 1 \"2020-07-01\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", manpage); + fputs(".SH NAME\n", manpage); + fprintf(manpage, "%s\n", pcmd->cmd); + + fputs("\n.SH DESCRIPTION\n", manpage); + fprintf(manpage, "%s\n", pcmd->help.desc); + + fputs("\n.SH SYNOPSIS\n", manpage); + int i = 0; + while (pcmd->help.synopsis[i]) { + fprintf(manpage, "%s\n", pcmd->help.synopsis[i]); + fputs("\n.BR\n", manpage); + i++; + } + + if (pcmd->help.args[0][0] != NULL) { + fputs("\n.SH ARGUMENTS\n", manpage); + for (i = 0; pcmd->help.args[i][0] != NULL; i++) { + fprintf(manpage, "%s\n", pcmd->help.args[i][0]); + fprintf(manpage, "%s\n", pcmd->help.args[i][1]); + fputs("\n.BR\n", manpage); + } + } + + if (pcmd->help.examples[0] != NULL) { + fputs("\n.SH EXAMPLES\n", manpage); + int i = 0; + while (pcmd->help.examples[i]) { + fprintf(manpage, "%s\n", pcmd->help.examples[i]); + fputs("\n.BR\n", manpage); + i++; + } + } + + curr = g_list_next(curr); + + fclose(manpage); + } + + printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); + g_list_free(cmds); +} diff --git a/src/command/cmd_defs.h b/src/command/cmd_defs.h index 32167c6d..c288d8b0 100644 --- a/src/command/cmd_defs.h +++ b/src/command/cmd_defs.h @@ -50,6 +50,7 @@ GList* cmd_get_ordered(const char* const tag); gboolean cmd_valid_tag(const char* const str); void command_docgen(void); +void command_mangen(void); GList* cmd_search_index_all(char* term); GList* cmd_search_index_any(char* term); diff --git a/src/main.c b/src/main.c index b7e2f6dd..d2027590 100644 --- a/src/main.c +++ b/src/main.c @@ -69,9 +69,14 @@ static char* theme_name = NULL; int main(int argc, char** argv) { - if (argc == 2 && g_strcmp0(argv[1], "docgen") == 0 && g_strcmp0(PACKAGE_STATUS, "development") == 0) { - command_docgen(); - return 0; + if (argc == 2 && g_strcmp0(PACKAGE_STATUS, "development") == 0) { + if (g_strcmp0(argv[1], "docgen") == 0) { + command_docgen(); + return 0; + } else if (g_strcmp0(argv[1], "mangen") == 0) { + command_mangen(); + return 0; + } } static GOptionEntry entries[] = { From 01b90064afdd0df62acd8b7e9a79716b3785157d Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 4 Dec 2020 17:48:45 +0100 Subject: [PATCH 2/7] Install all profanity manpages Regular profanity.1 and profanity-command.1 for each command. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 1228e1ad..5a4d8ffb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -213,7 +213,7 @@ icons_sources = $(top_srcdir)/icons/* script_sources = bootstrap.sh -man_sources = docs/profanity.1 +man_sources = docs/profanity*.1 if BUILD_PGP core_sources += $(pgp_sources) From 300b60722ba75beefc9f77ffece5ebbf4f8240b8 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 4 Dec 2020 17:50:30 +0100 Subject: [PATCH 3/7] Mention new manpages in main manpage --- docs/profanity.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/profanity.1 b/docs/profanity.1 index 291d8335..26a77a1d 100644 --- a/docs/profanity.1 +++ b/docs/profanity.1 @@ -46,6 +46,7 @@ The user guide can be found at . .B Profanity itself has a lot of built\-in help. Check the /help command for more information. Type "/help help" for information on how to use help itself. +Profanity ships with one man page for each built-in command. For /account there is man profanity-account. .SH CONFIGURATION Configuration for .B Profanity From b1d0d6d0c35cdef01dcc07c914ec8a2a42a32586 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:38:29 +0100 Subject: [PATCH 4/7] man: formate arguments properly --- src/command/cmd_defs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index e12fdb8a..4ea9d107 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2876,9 +2876,8 @@ command_mangen(void) if (pcmd->help.args[0][0] != NULL) { fputs("\n.SH ARGUMENTS\n", manpage); for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fprintf(manpage, "%s\n", pcmd->help.args[i][0]); - fprintf(manpage, "%s\n", pcmd->help.args[i][1]); - fputs("\n.BR\n", manpage); + fprintf(manpage, ".PP\n%s\n", pcmd->help.args[i][0]); + fprintf(manpage, ".RS 4\n%s\n.RE\n", pcmd->help.args[i][1]); } } From c833bd7feaaaec3f9a5e8e48bba3df7aa521189f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:45:17 +0100 Subject: [PATCH 5/7] Break lines differently in example and synopsis section --- src/command/cmd_defs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 4ea9d107..beaabac7 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2869,7 +2869,7 @@ command_mangen(void) int i = 0; while (pcmd->help.synopsis[i]) { fprintf(manpage, "%s\n", pcmd->help.synopsis[i]); - fputs("\n.BR\n", manpage); + fputs("\n.LP\n", manpage); i++; } @@ -2886,7 +2886,7 @@ command_mangen(void) int i = 0; while (pcmd->help.examples[i]) { fprintf(manpage, "%s\n", pcmd->help.examples[i]); - fputs("\n.BR\n", manpage); + fputs("\n.LP\n", manpage); i++; } } From 377a7b8e83f6d96e66801cc381f783bd14fd49ca Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 16:58:09 +0100 Subject: [PATCH 6/7] Generate date for manpage --- src/command/cmd_defs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index beaabac7..fba0e89e 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2846,6 +2846,16 @@ command_mangen(void) mkdir_recursive("docs"); + char* header = NULL; + GDateTime *now = g_date_time_new_now_local(); + gchar *date = g_date_time_format(now, "%F"); + if (asprintf(&header, ".TH man 1 \"%s\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", date) == -1) { + // TODO: error + return; + } + g_date_time_unref(now); + g_free(date); + GList* curr = cmds; while (curr) { Command* pcmd = curr->data; @@ -2858,7 +2868,7 @@ command_mangen(void) FILE* manpage = fopen(filename, "w"); free(filename); - fputs(".TH man 1 \"2020-07-01\" \""PACKAGE_VERSION"\" \"Profanity XMPP client\"\n", manpage); + fprintf(manpage, "%s\n", header); fputs(".SH NAME\n", manpage); fprintf(manpage, "%s\n", pcmd->cmd); @@ -2891,11 +2901,12 @@ command_mangen(void) } } - curr = g_list_next(curr); - fclose(manpage); + curr = g_list_next(curr); } printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); + + free(header); g_list_free(cmds); } From 1bbdaec8e7eb3d4f6ef3238c9365e2ea49618123 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 7 Dec 2020 17:25:22 +0100 Subject: [PATCH 7/7] Print man page arguments bold --- src/command/cmd_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index fba0e89e..51772a27 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2886,7 +2886,7 @@ command_mangen(void) if (pcmd->help.args[0][0] != NULL) { fputs("\n.SH ARGUMENTS\n", manpage); for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fprintf(manpage, ".PP\n%s\n", pcmd->help.args[i][0]); + fprintf(manpage, ".PP\n\\fB%s\\fR\n", pcmd->help.args[i][0]); fprintf(manpage, ".RS 4\n%s\n.RE\n", pcmd->help.args[i][1]); } }