From 329e819e1540de3b9ad22ce5f7a1192e0b4b6527 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 1 Jun 2022 13:59:52 +0200 Subject: [PATCH 1/2] feat(console): added command to generate man pages --- .gitignore | 1 + CHANGELOG.md | 2 ++ Makefile | 5 +++++ PKGBUILD | 3 +++ PKGBUILD.dev | 3 +++ src/console/console.v | 14 ++++++++++++++ src/console/man/man.v | 21 +++++++++++++++++++++ src/main.v | 2 ++ 8 files changed, 51 insertions(+) create mode 100644 src/console/man/man.v diff --git a/.gitignore b/.gitignore index f27a43f3..4d9f94f2 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ gdb.txt # Generated docs _docs/ +/man/ diff --git a/CHANGELOG.md b/CHANGELOG.md index affd5c4e..91f1ef57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * GitRepo: filter by repo * BuildLog: filter by start & end date, repo, exit code & arch * CLI flags to take advantage of above API improvements +* Added CLI command to generate all man pages +* PKGBUILDs now install man pages ### Changed diff --git a/Makefile b/Makefile index 199b99e6..7eb35472 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,11 @@ api-docs: rm -rf '$(SRC_DIR)/_docs' cd '$(SRC_DIR)' && v doc -all -f html -m -readme . +.PHONY: man +man: vieter + rm -rf man + ./vieter man man + # =====OTHER===== .PHONY: lint diff --git a/PKGBUILD b/PKGBUILD index 49fcf548..0296dbd6 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -24,4 +24,7 @@ package() { install -dm755 "$pkgdir/usr/bin" install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter" + + install -dm755 "$pkgdir/usr/share/man/man1" + ./vieter man "$pkgdir/usr/share/man/man1" } diff --git a/PKGBUILD.dev b/PKGBUILD.dev index d0176d86..6d95136a 100644 --- a/PKGBUILD.dev +++ b/PKGBUILD.dev @@ -32,4 +32,7 @@ package() { install -dm755 "$pkgdir/usr/bin" install -Dm755 "$pkgname/pvieter" "$pkgdir/usr/bin/vieter" + + install -dm755 "$pkgdir/usr/share/man/man1" + ./vieter man "$pkgdir/usr/share/man/man1" } diff --git a/src/console/console.v b/src/console/console.v index dfb2fac8..7d782bac 100644 --- a/src/console/console.v +++ b/src/console/console.v @@ -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)? + } +} diff --git a/src/console/man/man.v b/src/console/man/man.v new file mode 100644 index 00000000..d91a140f --- /dev/null +++ b/src/console/man/man.v @@ -0,0 +1,21 @@ +module man + +import cli +import console +import os + +// cmd returns the cli submodule that handles generating man pages. +pub fn cmd() cli.Command { + return cli.Command{ + name: 'man' + description: 'Generate all man pages & save them in the given directory.' + usage: 'dir' + required_args: 1 + execute: fn (cmd cli.Command) ? { + root := cmd.root() + os.mkdir_all(cmd.args[0])? + + console.export_man_pages(root, cmd.args[0])? + } + } +} diff --git a/src/main.v b/src/main.v index 885e0f32..80c19556 100644 --- a/src/main.v +++ b/src/main.v @@ -6,6 +6,7 @@ import cli import console.git import console.logs import console.schedule +import console.man import cron fn main() { @@ -29,6 +30,7 @@ fn main() { cron.cmd(), logs.cmd(), schedule.cmd(), + man.cmd(), ] } app.setup() From e5582a2d54aa59a4ea8c0982998c27d559c821d8 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 2 Jun 2022 17:26:03 +0200 Subject: [PATCH 2/2] ci: deploy man pages to website --- .woodpecker/.man.yml | 36 ++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 1 + 2 files changed, 37 insertions(+) create mode 100644 .woodpecker/.man.yml diff --git a/.woodpecker/.man.yml b/.woodpecker/.man.yml new file mode 100644 index 00000000..0b808866 --- /dev/null +++ b/.woodpecker/.man.yml @@ -0,0 +1,36 @@ +platform: 'linux/amd64' +branches: + exclude: [ main ] + +depends_on: + - build + +skip_clone: true + +pipeline: + generate: + image: 'chewingbever/vlang:latest' + pull: true + commands: + - curl -o vieter -L "https://s3.rustybever.be/vieter/commits/$CI_COMMIT_SHA/vieter-linux-amd64" + - chmod +x vieter + - ./vieter man man + - cd man + + # Generate an HTML page from each man page + - for f in $(ls -1 *.1); do mandoc -Thtml -O style=mandoc.css,man=%N.%S.html $f > "$f.html"; done + + # Download the mandoc.css file from the official site + - curl -o mandoc.css -L https://mandoc.bsd.lv/mandoc.css + + - tar czvf ../man.tar.gz *.html mandoc.css + + deploy: + image: 'curlimages/curl' + secrets: + - 'site_api_key' + commands: + - 'curl -XPOST --fail -s -H "Authorization: Bearer $SITE_API_KEY" -T man.tar.gz https://rustybever.be/api/deploy?dir=man-vieter' + when: + event: push + branch: dev diff --git a/CHANGELOG.md b/CHANGELOG.md index 91f1ef57..93e566a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * CLI flags to take advantage of above API improvements * Added CLI command to generate all man pages * PKGBUILDs now install man pages +* CLI man pages are now hosted on https://rustybever.be ### Changed