Skip to main content

cargo_xcode_build_rs/
cli.rs

1use crate::prelude::*;
2use clap::{Args, Parser, Subcommand};
3
4#[derive(Parser, Debug)]
5#[command(version, about)]
6#[command(name = "cargo", bin_name = "cargo")]
7pub enum TopLevel {
8	#[clap(name = "xcode-build-rs")]
9	XCodeBuild(XcodeBuild),
10}
11
12impl TopLevel {
13	fn inner(&self) -> &XcodeBuild {
14		match self {
15			TopLevel::XCodeBuild(inner) => inner,
16		}
17	}
18}
19
20#[derive(clap::Args, Debug)]
21#[command(version, about)]
22pub struct XcodeBuild {
23	#[clap(subcommand)]
24	mode: Mode,
25
26	#[clap(flatten)]
27	options: Options,
28}
29
30impl TopLevel {
31	pub fn options(&self) -> &Options {
32		&self.inner().options
33	}
34
35	pub fn mode(&self) -> &Mode {
36		&self.inner().mode
37	}
38}
39
40#[derive(Subcommand, Clone, Debug)]
41pub enum Mode {
42	/// Run in XCode
43	Xcode,
44	/// Run a test build for an iOS simulator
45	Test,
46}
47
48#[derive(Args, Debug)]
49pub struct Options {
50	/// By default, doesn't display colour because this can be annoying in the XCode terminal
51	#[arg(long, alias = "colour")]
52	pub colour: bool,
53
54	/// The --manifest-path option to pass to `cargo rustc builds`.
55	/// Often you can pass `.`
56	#[arg(long, alias = "manifest-dir")]
57	manifest_dir: Utf8PathBuf,
58}
59
60impl Options {
61	/// Specifically to the *file* `Cargo.toml`, *not directory*
62	pub fn manifest_path(&self) -> Utf8PathBuf {
63		self.manifest_dir.to_owned().join("Cargo.toml")
64	}
65}