bee_tui/cli.rs
1use std::path::PathBuf;
2
3use clap::Parser;
4
5use crate::config::{get_config_dir, get_data_dir};
6
7#[derive(Parser, Debug)]
8#[command(author, version = version(), about)]
9pub struct Cli {
10 /// Tick rate, i.e. number of ticks per second
11 #[arg(short, long, value_name = "FLOAT", default_value_t = 4.0)]
12 pub tick_rate: f64,
13
14 /// Frame rate, i.e. number of frames per second
15 #[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)]
16 pub frame_rate: f64,
17
18 /// Render with ASCII glyphs only — no Unicode (✓ ⚠ ✗ ▶ ▇ …).
19 /// Use on terminals with poor Unicode support: Windows Terminal
20 /// pre-Win11, screen readers, some SSH chains. Equivalent to
21 /// setting `[ui].ascii_fallback = true` in `config.toml`.
22 #[arg(long)]
23 pub ascii: bool,
24
25 /// Suppress colour output regardless of the configured theme.
26 /// Equivalent to setting `[ui].theme = "mono"` in `config.toml`,
27 /// or to `NO_COLOR=1` in the environment (which is also honoured
28 /// automatically per <https://no-color.org>).
29 #[arg(long)]
30 pub no_color: bool,
31
32 /// Path to a `bee` binary to spawn before opening the cockpit.
33 /// When set together with `--bee-config`, bee-tui starts Bee as
34 /// a child process, captures its log into a temp file, waits for
35 /// the API to come up, then opens the cockpit. Overrides
36 /// `[bee].bin` from `config.toml`.
37 #[arg(long, value_name = "PATH")]
38 pub bee_bin: Option<PathBuf>,
39
40 /// Path to the Bee YAML config the spawned binary should use.
41 /// Required when `--bee-bin` is set unless `[bee].config` is
42 /// already in `config.toml`. Overrides `[bee].config`.
43 #[arg(long, value_name = "PATH")]
44 pub bee_config: Option<PathBuf>,
45
46 /// Run a single verb without launching the TUI. Prints the
47 /// result on stdout and exits with `0` (ok), `1` (unhealthy /
48 /// failed), or `2` (usage error). Designed for CI / shell
49 /// pipelines: `bee-tui --once readiness` is the canonical
50 /// "is my Bee node ready for traffic?" smoke test.
51 ///
52 /// Supported verbs: `hash`, `cid`, `depth-table`, `pss-target`,
53 /// `gsoc-mine`, `readiness`, `version-check`, `inspect`,
54 /// `durability-check`. Trailing positional args go to the verb.
55 #[arg(long, value_name = "VERB")]
56 pub once: Option<String>,
57
58 /// When `--once` is set, emit a single JSON object on stdout
59 /// instead of the human-readable line. Field shape: `{ verb,
60 /// status, message, data }`. Lets CI parse the result without
61 /// regex on the human line.
62 #[arg(long)]
63 pub json: bool,
64
65 /// Trailing positional args consumed by `--once <verb>`. Not
66 /// used in TUI mode.
67 #[arg(trailing_var_arg = true)]
68 pub once_args: Vec<String>,
69}
70
71const VERSION_MESSAGE: &str = concat!(
72 env!("CARGO_PKG_VERSION"),
73 "-",
74 env!("VERGEN_GIT_DESCRIBE"),
75 " (",
76 env!("VERGEN_BUILD_DATE"),
77 ")"
78);
79
80pub fn version() -> String {
81 let author = clap::crate_authors!();
82
83 // let current_exe_path = PathBuf::from(clap::crate_name!()).display().to_string();
84 let config_dir_path = get_config_dir().display().to_string();
85 let data_dir_path = get_data_dir().display().to_string();
86
87 format!(
88 "\
89{VERSION_MESSAGE}
90
91Authors: {author}
92
93Config directory: {config_dir_path}
94Data directory: {data_dir_path}"
95 )
96}