greentic-pack 0.4.25

Greentic pack builder and reader
Documentation
use std::path::PathBuf;

use anyhow::Result;
use clap::{Args, Parser, Subcommand};

#[path = "common/events.rs"]
mod events;
#[path = "common/input.rs"]
mod input;
#[path = "common/inspect.rs"]
mod inspect;
#[path = "common/plan.rs"]
mod plan_cmd;

#[derive(Parser, Debug)]
#[command(name = "greentic-pack", version, about = "Greentic pack utilities")]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand, Debug)]
enum Command {
    /// Inspect a .gtpack archive and display verification info.
    Inspect(InspectArgs),
    /// Generate a DeploymentPlan from a pack archive or source directory.
    Plan(PlanArgs),
    /// Events-related helpers.
    #[command(subcommand)]
    Events(EventsCommand),
}

#[derive(Args, Debug)]
struct InspectArgs {
    /// Path to the .gtpack file
    #[arg(value_name = "FILE")]
    path: PathBuf,

    /// Signature policy to enforce
    #[arg(long, value_enum, default_value_t = inspect::PolicyArg::Devok)]
    policy: inspect::PolicyArg,

    /// Emit JSON output
    #[arg(long)]
    json: bool,
}

#[derive(Args, Debug)]
struct PlanArgs {
    /// Path to a .gtpack archive or pack source directory.
    #[arg(value_name = "PATH")]
    input: PathBuf,

    /// Tenant identifier to embed in the plan.
    #[arg(long, default_value = "tenant-local")]
    tenant: String,

    /// Environment identifier to embed in the plan.
    #[arg(long, default_value = "local")]
    environment: String,

    /// Emit compact JSON output instead of pretty-printing.
    #[arg(long)]
    json: bool,

    /// When set, print additional diagnostics (for directory builds).
    #[arg(long)]
    verbose: bool,
}

#[derive(Subcommand, Debug)]
enum EventsCommand {
    /// List event providers declared in a pack.
    List(EventsListArgs),
}

#[derive(Args, Debug)]
struct EventsListArgs {
    /// Path to a .gtpack archive or pack source directory.
    #[arg(value_name = "PATH")]
    path: PathBuf,

    /// Output format: table (default), json, yaml.
    #[arg(long, value_enum, default_value_t = events::OutputFormat::Table)]
    format: events::OutputFormat,

    /// When set, print additional diagnostics (for directory builds).
    #[arg(long)]
    verbose: bool,
}

fn main() -> Result<()> {
    let cli = Cli::parse();
    match cli.command {
        Command::Inspect(args) => inspect::run(&args.path, args.policy, args.json),
        Command::Plan(args) => plan_cmd::run(&args),
        Command::Events(cmd) => match cmd {
            EventsCommand::List(args) => events::list(&args),
        },
    }
}