rustuse-cli 0.2.0-beta.1

Command-line tooling for adopting, managing, and maintaining RustUse crates.
Documentation
//! Provides maintainer workflows for inspecting, reporting on, and repairing RustUse repositories.

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

use crate::output::Output;

pub mod check;
pub mod fix;
pub mod inspect;
pub mod interactive;
pub mod new;
pub mod report;

#[derive(Debug, Args)]
pub struct DevArgs {
    #[command(subcommand)]
    pub command: Option<DevCommands>,
}

#[derive(Debug, Subcommand)]
pub enum DevCommands {
    /// Run checks on one RustUse facade repository.
    Check(check::DevCheckArgs),

    /// Run fixes on one RustUse facade repository.
    Fix(fix::DevFixArgs),

    /// Inspect one RustUse facade repository.
    Inspect(inspect::DevInspectArgs),

    /// Create a new RustUse facade repository.
    New(new::DevNewArgs),

    /// Generate a RustUse development report.
    Report(report::DevReportArgs),
}

#[derive(Clone, Copy, Debug)]
pub(crate) struct DevCommandContext {
    pub non_interactive: bool,
    pub yes: bool,
}

pub fn run(args: DevArgs, output: Output, non_interactive: bool, yes: bool) -> Result<()> {
    let context = DevCommandContext {
        non_interactive,
        yes,
    };

    match args.command {
        Some(command) => run_command(command, output, context),
        None => interactive::run(output, context),
    }
}

fn run_command(command: DevCommands, output: Output, context: DevCommandContext) -> Result<()> {
    match command {
        DevCommands::Check(args) => check::run(args, output),
        DevCommands::Fix(args) => fix::run(args, output),
        DevCommands::Inspect(args) => inspect::run(args, output),
        DevCommands::New(args) => new::run(args, output),
        DevCommands::Report(args) => report::run(args, output, context),
    }
}