P0: config, DTOs, source traits, fakes, error, state and module stubs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-15 17:23:17 -04:00
1 parent aa9b0da962
commit 1802f97d94
22 files changed
+1736

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
//! `slinuxm` entry point: parse CLI, load layered config, dispatch.
//!
//! Phase 3 (I1) replaces the body of `serve` with the real wiring.
use std::net::IpAddr;
use std::path::PathBuf;
use anyhow::{bail, Context, Result};
use clap::{Parser, Subcommand};
use skyg_linux_tracker::auth::tokens::{self, TokenCmd};
use skyg_linux_tracker::config::{CliOverrides, Config};
#[derive(Debug, Parser)]
#[command(name = "slinuxm", version, about = "Read-only Linux system monitor")]
struct Cli {
/// Config file (default: /etc/skyg-linux-tracker.toml if present).
#[arg(long, global = true, env = "SKYG_CONFIG")]
config: Option<PathBuf>,
/// Print the effective merged configuration and exit.
#[arg(long, global = true)]
print_config: bool,
/// Listen address (server.bind).
#[arg(long, global = true)]
bind: Option<IpAddr>,
/// Listen port (server.port).
#[arg(long, global = true)]
port: Option<u16>,
/// Enable or disable auth (auth.enabled).
#[arg(long, global = true, value_name = "BOOL")]
auth_enabled: Option<bool>,
/// SQLite token database (auth.db_path).
#[arg(long, global = true)]
db_path: Option<PathBuf>,
/// Docker socket (sources.docker_socket).
#[arg(long, global = true)]
docker_socket: Option<PathBuf>,
/// Journal namespace (sources.journal_namespace).
#[arg(long, global = true)]
journal_namespace: Option<String>,
/// Enable or disable OTel export (otel.enabled).
#[arg(long, global = true, value_name = "BOOL")]
otel_enabled: Option<bool>,
/// OTLP endpoint (otel.endpoint).
#[arg(long, global = true)]
otel_endpoint: Option<String>,
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Run the server (default).
Serve,
/// Manage API access tokens.
Token {
#[command(subcommand)]
cmd: TokenCmd,
},
}
impl Cli {
fn overrides(&self) -> CliOverrides {
CliOverrides {
bind: self.bind,
port: self.port,
auth_enabled: self.auth_enabled,
db_path: self.db_path.clone(),
docker_socket: self.docker_socket.clone(),
journal_namespace: self.journal_namespace.clone(),
otel_enabled: self.otel_enabled,
otel_endpoint: self.otel_endpoint.clone(),
}
}
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let config = Config::load(cli.config.as_deref(), &cli.overrides())?;
if cli.print_config {
print!(
"{}",
config.to_toml_redacted().context("serializing config")?
);
return Ok(());
}
match cli.command.unwrap_or(Command::Serve) {
Command::Serve => serve(config).await,
Command::Token { cmd } => tokens::run(cmd, &config).await,
}
}
async fn serve(config: Config) -> Result<()> {
// Phase 3 (I1): telemetry::init, db::open, AppState::live, router wiring,
// graceful shutdown. Until then, config validation is all `serve` does.
bail!(
"server wiring is not implemented yet (P3 I1); config is valid, bind = {}:{}",
config.server.bind,
config.server.port
)
}