mecha10-cli 0.6.5

Mecha10 CLI tool
Documentation
//! Logs command arguments

use clap::{Args, Subcommand};

/// Logs subcommands
///
/// Mirrors `RunCommand`/`StopCommand`'s target-argument shape (see `commands::run`) so
/// `mecha10 logs <target>` pairs naturally with `mecha10 run <target>`/`mecha10 stop <target>`.
/// `Dev` wraps the pre-existing local log-file viewer (`mecha10 dev`'s nodes/framework/services
/// write to `<project>/logs`, no Docker involved); `Remote` is ported from the former
/// `mecha10 remote logs` - see `handlers::logs`.
#[derive(Subcommand, Debug)]
pub enum LogsCommand {
    /// View logs from mecha10 dev's node/framework/service log files
    Dev(#[command(flatten)] LogsArgs),

    /// View logs from the remote target's Docker Compose stack
    Remote(#[command(flatten)] LogsRemoteArgs),
}

/// Arguments for `logs dev`
#[derive(Args, Debug)]
pub struct LogsArgs {
    /// Optional node name to filter logs (e.g., "camera_driver")
    #[arg(value_name = "NODE")]
    pub node: Option<String>,

    /// Follow logs in real-time (default behavior, use --no-follow to disable)
    #[arg(short, long, default_value = "true", action = clap::ArgAction::SetTrue)]
    pub follow: bool,

    /// Disable follow mode (show static logs)
    #[arg(long, conflicts_with = "follow")]
    pub no_follow: bool,

    /// Filter logs by pattern (case-insensitive substring match)
    #[arg(short = 'g', long, value_name = "PATTERN")]
    pub filter: Option<String>,

    /// Number of lines to show (tail behavior)
    #[arg(short = 'n', long, value_name = "LINES", default_value = "100")]
    pub lines: Option<usize>,

    /// Log source type to display
    #[arg(short = 's', long, value_name = "SOURCE", value_enum)]
    pub source: Option<LogSource>,

    /// Show timestamps
    #[arg(short = 't', long)]
    pub timestamps: bool,

    /// Log level filter (error, warn, info, debug, trace)
    #[arg(long, value_name = "LEVEL")]
    pub level: Option<String>,
}

/// Log source types
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum LogSource {
    /// All log sources
    All,
    /// Node logs only
    Nodes,
    /// Framework/CLI logs
    Framework,
    /// Infrastructure services (Redis, PostgreSQL, etc.)
    Services,
}

/// Arguments for `logs remote` (ported from the former `mecha10 remote logs`)
#[derive(Args, Debug)]
pub struct LogsRemoteArgs {
    /// Specific node to view logs for (e.g., object-detector)
    /// If not specified, shows logs from all remote nodes
    pub node: Option<String>,

    /// Follow log output (like tail -f)
    #[arg(short, long)]
    pub follow: bool,

    /// Number of lines to show from the end
    #[arg(short = 'n', long, default_value = "100")]
    pub tail: u32,
}