1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00
attic/book/colorized-help.nix
2023-01-29 17:23:59 -07:00

44 lines
1 KiB
Nix

{ lib, stdenv, runCommand, attic, ansi2html }:
with builtins;
let
commands = {
attic = [
null
"login"
"use"
"push"
"watch-store"
"cache"
"cache create"
"cache configure"
"cache destroy"
"cache info"
];
atticd = [
null
];
atticadm = [
null
"make-token"
];
};
renderMarkdown = name: subcommands: ''
mkdir -p $out
(
ansi2html -H
${lib.concatMapStrings (subcommand: let
fullCommand = "${name} ${if subcommand == null then "" else subcommand}";
in "${renderCommand fullCommand}\n") subcommands}
) >>$out/${name}.md
'';
renderCommand = fullCommand: ''
echo '## `${fullCommand}`'
echo -n '<pre><div class="hljs">'
TERM=xterm-256color CLICOLOR_FORCE=1 ${fullCommand} --help | ansi2html -p
echo '</div></pre>'
'';
in runCommand "attic-colorized-help" {
nativeBuildInputs = [ attic ansi2html ];
} (concatStringsSep "\n" (lib.mapAttrsToList renderMarkdown commands))