1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use clap::{Parser, Subcommand, ValueEnum};
/// A high-performance command-line statistics tracker.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Prints the shell function used to integrate t_trace with shell.
Init(InitArgs),
/// Manage the t_trace background daemon process.
Daemon(DaemonArgs),
/// Display aggregated command statistics.
Stats {
/// Optionally filter the output to show only commands containing this phrase (case-insensitive).
#[arg(short = 'g', long = "grep")]
filter: Option<String>,
},
}
#[derive(Parser, Debug)]
pub struct InitArgs {
/// The target shell for which to generate the initialization script.
#[arg(value_enum)]
pub shell: Shell,
}
#[derive(ValueEnum, Clone, Debug)]
pub enum Shell {
Bash,
}
#[derive(Parser, Debug)]
pub struct DaemonArgs {
#[command(subcommand)]
pub command: DaemonCommands,
}
#[derive(Subcommand, Debug)]
pub enum DaemonCommands {
/// Start the daemon process in the background.
Run,
/// Stop the daemon process gracefully.
Stop,
/// Check if the daemon process is running and responsive.
HealthCheck,
/// Notify the daemon process that a command is beginning.
CommandBegin {
#[arg()]
pid: u32,
#[arg()]
command: String,
},
/// Notify the daemon process that a command has ended.
CommandEnd {
#[arg()]
pid: u32,
#[arg()]
exit_code: i32,
},
}