feat(console): added command to generate man pages

Jef Roosens 2022-06-01 13:59:52 +02:00
parent ec92b16a73
commit ae8884da53
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
5 changed files with 23 additions and 0 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ gdb.txt
# Generated docs # Generated docs
_docs/ _docs/
man/

View File

@ -24,4 +24,7 @@ package() {
install -dm755 "$pkgdir/usr/bin" install -dm755 "$pkgdir/usr/bin"
install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter" install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter"
install -dm755 "$pkgdir/usr/share/man/man1"
./vieter man "$pkgdir/usr/share/man/man1"
} }

View File

@ -32,4 +32,7 @@ package() {
install -dm755 "$pkgdir/usr/bin" install -dm755 "$pkgdir/usr/bin"
install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter" install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter"
install -dm755 "$pkgdir/usr/share/man/man1"
./vieter man "$pkgdir/usr/share/man/man1"
} }

View File

@ -2,6 +2,8 @@ module console
import arrays import arrays
import strings import strings
import cli
import os
// pretty_table converts a list of string data into a pretty table. Many thanks // pretty_table converts a list of string data into a pretty table. Many thanks
// to @hungrybluedev in the Vlang Discord for providing this code! // 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() 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)?
}
}

View File

@ -6,6 +6,7 @@ import cli
import console.git import console.git
import console.logs import console.logs
import console.schedule import console.schedule
import console.man
import cron import cron
fn main() { fn main() {
@ -29,6 +30,7 @@ fn main() {
cron.cmd(), cron.cmd(),
logs.cmd(), logs.cmd(),
schedule.cmd(), schedule.cmd(),
man.cmd(),
] ]
} }
app.setup() app.setup()