cnctd_cli 0.3.0

CLI for scaffolding and managing projects
use clap::Subcommand;

pub mod version;
pub mod build;
pub mod testflight;

#[derive(Subcommand, Debug)]
pub enum IosCommands {
    /// Show current version and build number
    Version {},

    /// Bump version (major/minor/patch) or build number
    Bump {
        /// Part to bump: "major", "minor", "patch", or "build" (default: build)
        #[arg(default_value = "build")]
        part: String,
    },

    /// Archive the app (xcodebuild archive)
    Archive {
        /// Build configuration (e.g., Release, Debug)
        #[arg(short, long, default_value = "Release")]
        configuration: String,
    },

    /// Export IPA from archive
    Export {
        /// Export method: "app-store", "ad-hoc", "development"
        #[arg(short, long, default_value = "app-store")]
        method: String,
    },

    /// Upload IPA to App Store Connect
    Upload {},

    /// Full pipeline: bump build -> archive -> export -> upload
    Release {
        /// Optional version bump (major/minor/patch). Build number always bumps.
        #[arg(short, long)]
        version: Option<String>,
    },

    /// Check build processing status on App Store Connect
    Status {
        /// App Store Connect app ID (or set ASC_APP_ID env var)
        #[arg(short, long)]
        app_id: Option<String>,
    },

    /// Add a TestFlight beta tester
    TestflightAdd {
        /// Tester email address
        email: String,

        /// Tester first name
        first_name: String,

        /// Tester last name
        last_name: String,
    },

    /// Remove a TestFlight beta tester
    TestflightRemove {
        /// Tester ID from App Store Connect
        tester_id: String,
    },
}

pub async fn route_ios_command(command: IosCommands) -> anyhow::Result<()> {
    match command {
        IosCommands::Version {} => {
            version::show_version().await?;
        }
        IosCommands::Bump { part } => {
            version::bump(&part).await?;
        }
        IosCommands::Archive { configuration } => {
            build::archive_app(&configuration).await?;
        }
        IosCommands::Export { method } => {
            build::export_app(&method).await?;
        }
        IosCommands::Upload {} => {
            build::upload_app().await?;
        }
        IosCommands::Release { version } => {
            build::release(version.as_deref()).await?;
        }
        IosCommands::Status { app_id } => {
            build::check_status(app_id.as_deref()).await?;
        }
        IosCommands::TestflightAdd {
            email,
            first_name,
            last_name,
        } => {
            testflight::add_tester(&email, &first_name, &last_name).await?;
        }
        IosCommands::TestflightRemove { tester_id } => {
            testflight::remove_tester(&tester_id).await?;
        }
    }
    Ok(())
}