sastri 0.1.0

Scaffold multi-ecosystem packaging and CI/CD for Rust CLIs (Homebrew, Scoop, PyPI, npm, Hex, mise, asdf, …)
Documentation
use std::path::PathBuf;
use std::process::ExitCode;

use anyhow::Result;
use clap::{Parser, Subcommand};
use tracing_subscriber::EnvFilter;

use sastri::config::SastriConfig;
use sastri::engine::registry;
use sastri::generate::{generate, GenerateOptions};
use sastri::secrets;
use sastri::wizard;

#[derive(Debug, Parser)]
#[command(
    name = "sastri",
    about = "Scaffold multi-ecosystem packaging & CI/CD for Rust CLIs",
    version
)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Debug, Subcommand)]
enum Commands {
    /// Interactive wizard → write Sastri.toml (non-sensitive) and optional generate
    Init {
        /// Output config path
        #[arg(long, default_value = "Sastri.toml")]
        config: PathBuf,
        /// Also run generate after the wizard
        #[arg(long)]
        generate: bool,
        /// Target crate / repo root to write packaging into
        #[arg(long, default_value = ".")]
        root: PathBuf,
    },
    /// Generate packaging + CI from an existing Sastri.toml
    Generate {
        #[arg(long, default_value = "Sastri.toml")]
        config: PathBuf,
        #[arg(long, default_value = ".")]
        root: PathBuf,
        /// Only run these mechanism ids (default: all enabled in config)
        #[arg(long)]
        only: Vec<String>,
        /// Skip the TUI progress view
        #[arg(long)]
        no_tui: bool,
        /// Overwrite existing generated files
        #[arg(long)]
        force: bool,
    },
    /// List built-in install mechanisms (and stubs for future ecosystems)
    Mechanisms,
    /// Print which GitHub / registry secrets are required (never stores values)
    Secrets {
        #[arg(long, default_value = "Sastri.toml")]
        config: PathBuf,
    },
}

fn main() -> ExitCode {
    tracing_subscriber::fmt()
        .with_env_filter(
            EnvFilter::from_default_env().add_directive("sastri=info".parse().unwrap()),
        )
        .with_writer(std::io::stderr)
        .init();

    match run() {
        Ok(()) => ExitCode::SUCCESS,
        Err(err) => {
            eprintln!("error: {err:#}");
            ExitCode::FAILURE
        }
    }
}

fn run() -> Result<()> {
    let cli = Cli::parse();
    match cli.command {
        Commands::Init {
            config,
            generate: do_generate,
            root,
        } => {
            let cfg = wizard::run_wizard(&config)?;
            cfg.save(&config)?;
            println!("wrote {}", config.display());
            if do_generate {
                generate(GenerateOptions {
                    config: cfg,
                    root,
                    only: None,
                    use_tui: true,
                    force: true,
                })?;
            } else {
                println!("next: sastri generate --config {}", config.display());
            }
        }
        Commands::Generate {
            config,
            root,
            only,
            no_tui,
            force,
        } => {
            let cfg = SastriConfig::load(&config)?;
            generate(GenerateOptions {
                config: cfg,
                root,
                only: if only.is_empty() { None } else { Some(only) },
                use_tui: !no_tui,
                force,
            })?;
        }
        Commands::Mechanisms => {
            for m in registry::all() {
                let status = if m.stable() { "stable" } else { "stub" };
                println!("{:<16} {:<8} {}", m.id(), status, m.description());
            }
        }
        Commands::Secrets { config } => {
            let cfg = SastriConfig::load(&config)?;
            secrets::print_checklist(&cfg);
        }
    }
    Ok(())
}