ez_tui/types/args.rs
1use clap::{Args, FromArgMatches, Parser};
2use std::fmt::Debug;
3use tracing::metadata::LevelFilter;
4
5/// Trait to be defined on your client's clap arguments enum.
6pub trait EzArgs: FromArgMatches + Args + Clone + Debug + 'static {}
7
8/// Wraps the library and your business logic command line arguments.
9#[derive(Debug, Parser, Clone)]
10#[clap(name = "red", version, about, long_about, long_help)]
11pub struct AppArguments<CA>
12where
13 CA: EzArgs,
14{
15 /// Arguments define by this library
16 #[clap(flatten)]
17 pub lib: CommonArg,
18
19 /// Arguments provided for your business logic. If you don't need any, you can use [`NoClientArgs`]
20 #[clap(flatten)]
21 pub client: CA,
22}
23
24/// Holds the command line arguments to change this lib behavior.
25#[derive(Parser, Debug, Clone)]
26#[command(author, version, about, long_about = None)]
27pub struct CommonArg {
28 /// The log level to use. Note that because we are in a TUI, we have no stdout; so as of now, logs are only available via the [`ez_tui_std_lib::LogsViewer`] component.
29 // FEAT: Alternate way to log. A file loger for sure ! Maybe a default component forced into the view ?
30 #[arg(long, alias = "log", default_value = "debug")]
31 pub log_level: LevelFilter,
32
33 /// The tick rate for the application. Will be set to the frame rate if not provided. Any value above frame rate rarely make sense as the application state will change quicker that it is rendered.
34 #[arg(long, alias = "tick")]
35 pub tick_rate: Option<u64>,
36
37 /// The rate at which the view is rendered in the terminal
38 #[arg(long, alias = "fps", default_value = "20")]
39 pub frame_rate: u64,
40}
41
42/// Dummy struct to use when you don't need any client arguments.
43#[derive(Debug, Parser, Clone)]
44pub struct NoClientArgs;
45impl EzArgs for NoClientArgs {}