1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

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.
This commit is contained in:
Michael Vetter 2020-12-04 17:29:31 +01:00
parent 35aecd425f
commit 5e99a791e6
4 changed files with 80 additions and 3 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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[] = {