feat(console): added command to generate man pages

This commit is contained in:
Jef Roosens 2022-06-01 13:59:52 +02:00 committed by Jef Roosens
parent 06df2c21f0
commit 329e819e15
Signed by untrusted user: Jef Roosens
GPG key ID: B580B976584B5F30
8 changed files with 51 additions and 0 deletions

View file

@ -2,6 +2,8 @@ module console
import arrays
import strings
import cli
import os
// pretty_table converts a list of string data into a pretty table. Many thanks
// to @hungrybluedev in the Vlang Discord for providing this code!
@ -54,3 +56,15 @@ pub fn pretty_table(header []string, data [][]string) ?string {
return buffer.str()
}
// export_man_pages recursively generates all man pages for the given
// cli.Command & writes them to the given directory.
pub fn export_man_pages(cmd cli.Command, path string) ? {
man := cmd.manpage()
os.write_file(os.join_path_single(path, cmd.full_name().replace(' ', '-') + '.1'),
man)?
for sub_cmd in cmd.commands {
export_man_pages(sub_cmd, path)?
}
}