pub mod cli_controller;
pub use cli_controller::Cli;
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Parser)]
pub struct Args {
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Subcommand)]
pub enum Command {
UI,
Generate {
#[arg(short, long)]
name: String,
#[arg(short, long)]
platform: Platform,
#[arg(short, long, default_value = "xctest")]
test_framework: TestFramework,
#[arg(short, long)]
files: Vec<OptionalFile>,
#[arg(long)]
open_xcode: bool,
},
}
pub async fn run(args: Args) -> Result<(), String> {
match args.command {
Some(Command::UI) => {
let _ = crate::ui::spm_view::run();
Ok(())
}
Some(Command::Generate {
name,
platform,
test_framework,
files,
open_xcode,
}) => {
crate::core::spm_builder::SpmBuilder::create(
&name,
&files,
&[platform.as_str()],
test_framework.as_str(),
)?;
println!("Package '{}' generated.", name);
if open_xcode {
crate::utils::xcode::open_xcode(&name)?;
}
Ok(())
}
None => {
let header = crate::header::Header::show();
println!("{header}");
Cli::execute_flow().await
}
}
}
#[derive(Clone, ValueEnum)]
pub enum Platform {
Ios,
Macos,
Tvos,
Watchos,
Visionos,
}
impl Platform {
pub fn as_str(&self) -> &'static str {
match self {
Platform::Ios => "iOS",
Platform::Macos => "macOS",
Platform::Tvos => "tvOS",
Platform::Watchos => "watchOS",
Platform::Visionos => "visionOS",
}
}
}
#[derive(Clone, ValueEnum)]
pub enum TestFramework {
Xctest,
SwiftTesting,
}
impl TestFramework {
pub fn as_str(&self) -> &'static str {
match self {
TestFramework::Xctest => "XCTest",
TestFramework::SwiftTesting => "Swift Testing",
}
}
}
#[derive(Clone, ValueEnum)]
pub enum OptionalFile {
Changelog,
Readme,
Spi,
Swiftlint,
}
impl OptionalFile {
pub fn as_str(&self) -> &'static str {
match self {
OptionalFile::Changelog => "Changelog",
OptionalFile::Readme => "Readme",
OptionalFile::Spi => "Swift Package Index",
OptionalFile::Swiftlint => "SwiftLint",
}
}
}
impl AsRef<str> for OptionalFile {
fn as_ref(&self) -> &str {
self.as_str()
}
}