obsidianlog_cli/cli.rs
1//! Command-line interface definition.
2//!
3//! The CLI is declared as a [`clap`] derive tree. Keeping it in the library lets
4//! the crate own its own argument surface and lets tests construct invocations
5//! directly.
6
7use std::path::PathBuf;
8
9use clap::{Args, Parser, Subcommand, ValueEnum};
10
11/// ObsidianLog: long-term, tamper-evident operational log archival on Sia.
12#[derive(Debug, Parser)]
13#[command(name = "obsidianlog", version, about, long_about = None)]
14pub struct Cli {
15 /// Path to the ObsidianLog config file (defaults to the platform config dir).
16 #[arg(long, short, global = true, value_name = "FILE")]
17 pub config: Option<PathBuf>,
18
19 #[command(subcommand)]
20 pub command: Command,
21}
22
23/// Top-level subcommands, mirroring the `obsidianlog <verb>` surface.
24#[derive(Debug, Subcommand)]
25pub enum Command {
26 /// Interactive setup wizard: generate keys, configure indexd, write config.
27 Init(InitArgs),
28
29 /// Run the Vector-compatible HTTP ingest server.
30 Serve(ServeArgs),
31
32 /// Query archived logs by time range, service, level, host, or keyword.
33 Query(QueryArgs),
34
35 /// Traverse and validate the full hash chain for tamper-evidence.
36 Verify(VerifyArgs),
37}
38
39/// Arguments for `obsidianlog init`.
40#[derive(Debug, Args)]
41pub struct InitArgs {
42 /// Run non-interactively, accepting defaults where possible.
43 #[arg(long)]
44 pub non_interactive: bool,
45
46 /// Overwrite an existing configuration if one is present.
47 #[arg(long)]
48 pub force: bool,
49}
50
51/// Arguments for `obsidianlog serve`.
52#[derive(Debug, Args)]
53pub struct ServeArgs {
54 /// Address to bind the HTTP ingest endpoint to (overrides the config file).
55 #[arg(long, value_name = "ADDR")]
56 pub bind: Option<String>,
57}
58
59/// Arguments for `obsidianlog query`.
60#[derive(Debug, Args)]
61pub struct QueryArgs {
62 /// Inclusive lower bound of the time range: RFC 3339, or relative to now
63 /// (e.g. `24h`, `30m`, `7d`).
64 #[arg(long, value_name = "TIME")]
65 pub from: Option<String>,
66
67 /// Inclusive upper bound of the time range: RFC 3339, or relative to now
68 /// (e.g. `1h`, `30m`, `7d`).
69 #[arg(long, value_name = "TIME")]
70 pub to: Option<String>,
71
72 /// Filter by service name.
73 #[arg(long, value_name = "NAME")]
74 pub service: Option<String>,
75
76 /// Filter by log level (e.g. info, warn, error).
77 #[arg(long, value_name = "LEVEL")]
78 pub level: Option<String>,
79
80 /// Filter by originating host.
81 #[arg(long, value_name = "HOST")]
82 pub host: Option<String>,
83
84 /// Free-text keyword to match within log lines.
85 #[arg(long, value_name = "TEXT")]
86 pub keyword: Option<String>,
87
88 /// Output format for matched records.
89 #[arg(long, value_enum, default_value_t = OutputFormat::Human)]
90 pub format: OutputFormat,
91}
92
93/// Arguments for `obsidianlog verify`.
94#[derive(Debug, Args)]
95pub struct VerifyArgs {
96 /// Restrict verification to a single service's chain.
97 #[arg(long, value_name = "NAME")]
98 pub service: Option<String>,
99}
100
101/// Rendering format for query results.
102#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
103pub enum OutputFormat {
104 /// Human-readable, colorized terminal output.
105 Human,
106 /// A pretty-printed, structured JSON array of matched records.
107 Json,
108 /// Raw decrypted log bytes, one JSON object per line, for piping to `jq`.
109 Raw,
110}