joularcore 0.1.0

Joular Core is a platform to measure power and energy across all systems, OSes and devices
Documentation
/*
 * Copyright (c) 2025-2026, Adel Noureddine.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the
 * GNU Lesser General Public License v3.0 only (LGPL-3.0-only)
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0.en.html
 *
 * Author : Adel Noureddine
 */

use crate::Component;
use clap::Parser;

#[derive(Parser)]
#[command(author, version, name = "Joular Core")]
pub struct Args {
    /// Monitor a specific process by its PID
    #[arg(short = 'p', long = "pid", conflicts_with = "app")]
    pub pid: Option<u32>,

    /// Monitor a specific application by its name (all PIDs)
    #[arg(short = 'a', long = "app")]
    pub app: Option<String>,

    /// Write output to CSV file
    #[arg(short = 'f', long = "file")]
    pub file: Option<String>,

    /// Monitor only specific component (cpu or gpu)
    #[arg(short = 'c', long = "component", value_enum)]
    pub component: Option<Component>,

    /// Output only numeric value (no formatting)
    #[arg(short = 'i', long = "numeric")]
    pub numeric_only: bool,

    /// Overwrite file instead of append (only with -f)
    #[arg(short = 'o', long = "overwrite", requires = "file")]
    pub overwrite: bool,

    /// Start GUI interface
    #[arg(
        short = 'g',
        long = "gui",
        conflicts_with_all = ["pid", "app", "file", "overwrite", "silent", "numeric_only"]
    )]
    pub gui: bool,

    /// Send power data to ring buffer
    #[arg(short = 'r', long = "ringbuffer")]
    pub ringbuffer: bool,

    /// Start API server on specified port
    #[arg(long = "api-port")]
    pub api_port: Option<u16>,

    /// Additional CORS-allowed origin for the API (repeatable). Localhost is always allowed.
    #[arg(
        long = "api-allowed-origin",
        value_name = "ORIGIN",
        requires = "api_port"
    )]
    pub api_allowed_origins: Vec<String>,

    /// Disable the live terminal power line while keeping other outputs active
    #[arg(short = 's', long = "silent")]
    pub silent: bool,

    /// CPU idle baseline in Watts to subtract before attributing PID/app power
    #[arg(
        long = "cpu-idle-baseline",
        value_name = "WATTS",
        default_value_t = 0.0,
        conflicts_with = "calibrate_cpu_idle_baseline"
    )]
    pub cpu_idle_baseline: f64,

    /// Refresh interval in seconds for application PID sweeping (0 to disable caching)
    #[arg(
        long = "app-refresh-interval",
        value_name = "SECONDS",
        default_value_t = 3
    )]
    pub app_refresh_interval: u64,

    /// Calibrate the CPU idle baseline from a short idle measurement window
    #[arg(long = "calibrate-cpu-idle-baseline")]
    pub calibrate_cpu_idle_baseline: bool,
}