abbaye/cli.rs
1use std::path::PathBuf;
2
3use clap::Parser;
4use clap::Subcommand;
5
6pub const RESET: &str = "\x1b[0m";
7
8pub const RED: &str = "\x1b[31m";
9pub const GREEN: &str = "\x1b[32m";
10pub const YELLOW: &str = "\x1b[33m";
11pub const BLUE: &str = "\x1b[34m";
12pub const MAGENTA: &str = "\x1b[35m";
13pub const CYAN: &str = "\x1b[36m";
14
15/// Array to cycle through ANSI color escape codes for builder spinner prefixes.
16pub const COLOURS: &[&str] = &[CYAN, GREEN, YELLOW, MAGENTA, BLUE, RED];
17
18#[derive(Parser, Debug)]
19#[command(author, version, about, long_about = None)]
20pub struct CliArgs {
21 /// Verbosity level (0 = normal, 1 = verbose, 2 = debug)
22 #[arg(short, long, default_value_t = 0, action=clap::ArgAction::Count)]
23 pub verbose: u8,
24 #[command(subcommand)]
25 pub command: CliCommand,
26}
27
28#[derive(Subcommand, Debug, Clone)]
29pub enum CliCommand {
30 /// Initialize a new abbaye.toml file
31 Init {
32 /// path to directory to initialize in
33 path: Option<PathBuf>,
34 },
35 /// Build the site
36 Build {
37 /// Only regenerate the git repository web UI; skip the version page builds.
38 /// Requires `[git_ui]` to be configured in `abbaye.toml`.
39 #[arg(long)]
40 repository_only: bool,
41 },
42 /// Build the site for every git tag, starting from the lowest semver version.
43 /// Checks out each tag in order, builds, then restores the original HEAD.
44 BuildAll,
45 /// Dumps the default theme to `.abbaye/theme` so you can inspect and modify it. It will be used afterwards when building the site.
46 DumpTheme,
47 /// Print a JSON Schema for `abbaye.toml` to stdout.
48 ///
49 /// Redirect the output to a file (e.g. `abbaye dump-schema > abbaye.schema.json`) and
50 /// point your editor or TOML language server at it to get field descriptions and
51 /// auto-completion while editing `abbaye.toml`.
52 DumpSchema,
53 /// Check for a newer version of abbaye and update the binary if one is available.
54 SelfUpdate {
55 /// Only check whether an update is available; do not download or replace the binary.
56 #[arg(short, long)]
57 check: bool,
58 },
59 /// Print a usage spec (https://usage.jdx.dev) to stdout.
60 ///
61 /// Pipe the output to the `usage` CLI to generate shell completions, man pages, or docs:
62 /// `abbaye usage-spec | usage generate completion bash`
63 /// `abbaye usage-spec | usage generate manpage --out-file abbaye.1`
64 #[command(hide = true)]
65 UsageSpec,
66}