apple_clis/
cli.rs

1use crate::prelude::*;
2
3use crate::{ios_deploy::detect::DetectDevicesConfig, open::well_known::WellKnown, xcrun::simctl};
4
5pub mod run;
6
7pub use app_path::AppPathArgs;
8mod app_path;
9pub use device_name::{DeviceSimulatorBootedArgs, DeviceSimulatorUnBootedArgs};
10mod device_name;
11pub use bundle_identifier::BundleIdentifierArgs;
12mod bundle_identifier;
13
14#[derive(Parser, Debug)]
15#[command(version, about, long_about = None)]
16#[command(propagate_version = true)]
17pub struct CliArgs {
18	#[command(flatten)]
19	pub args: TopLevelCliArgs,
20
21	#[command(subcommand)]
22	pub command: Commands,
23}
24
25#[derive(Args, Debug)]
26#[group(required = false, multiple = false)]
27pub struct TopLevelCliArgs {
28	/// Outputs data as JSON. Aliased to --json.
29	/// Is global, hence can be used with any command/subcommand except help messages
30	#[arg(long, global = true, group = "top_level_args", alias = "json")]
31	machine: bool,
32
33	/// Overrides the RUST_LOG env variable to use a very verbose log level
34	#[arg(long, global = true, group = "top_level_args")]
35	verbose: bool,
36
37	/// Only displays warnings and errors
38	#[arg(long, short, global = true, group = "top_level_args")]
39	quiet: bool,
40}
41
42impl TopLevelCliArgs {
43	pub fn machine(&self) -> bool {
44		self.machine
45	}
46
47	pub fn human(&self) -> bool {
48		!self.machine()
49	}
50
51	pub fn verbose(&self) -> bool {
52		self.verbose
53	}
54
55	pub fn quiet(&self) -> bool {
56		self.quiet
57	}
58}
59
60#[derive(Subcommand, Debug)]
61pub enum Commands {
62	/// Used for setting up completions
63	#[clap(subcommand)]
64	Init(Init),
65
66	#[clap(subcommand)]
67	IosDeploy(IosDeploy),
68
69	// #[clap(subcommand)]
70	// CargoBundle(CargoBundle),
71	#[clap(subcommand)]
72	Security(Security),
73
74	#[clap(subcommand)]
75	Spctl(Spctl),
76
77	#[clap(subcommand, name = "codesign")]
78	CodeSign(CodeSign),
79
80	#[clap(subcommand, name = "xcrun")]
81	XcRun(XcRun),
82
83	Open(#[clap(flatten)] Open),
84}
85
86#[derive(Subcommand, Debug)]
87pub enum Init {
88	#[clap(name = "nushell")]
89	#[group(required = true)]
90	NuShell {
91		/// Automatically adds shell completions to `~/.apple-clis.nu`
92		/// and configures your config.nu file to source it.
93		/// This is the recommended approach.
94		#[arg(long, group = "init")]
95		auto: bool,
96
97		/// Run `apple-clis init nushell --raw-script | save -f ~/.apple-clis.nu`
98		/// Then add `source ~/.apple-clis.nu` to your config.nu file,
99		/// E.g. `"source ~/.apple-clis.nu" | save --append $nu.config-path`
100		#[arg(long, group = "init")]
101		raw_script: bool,
102	},
103}
104
105#[derive(Subcommand, Debug)]
106pub enum IosDeploy {
107	/// Spends a second to detect any already connected devices
108	Detect {
109		#[clap(flatten)]
110		config: DetectDevicesConfig,
111	},
112	/// Uploads an app to a real device
113	Upload {
114		#[clap(flatten)]
115		app_path: app_path::AppPathArgs,
116
117		#[clap(flatten)]
118		auto_detect_config: DetectDevicesConfig,
119	},
120}
121
122#[derive(Subcommand, Debug)]
123pub enum CargoBundle {
124	/// Bundles the iOS app
125	Ios,
126}
127
128#[derive(Subcommand, Debug)]
129pub enum Security {
130	Certs,
131	Pems,
132}
133
134#[derive(Subcommand, Debug)]
135pub enum CodeSign {
136	/// Displays the code signature of the given file
137	Display {
138		#[clap(flatten)]
139		app_path: AppPathArgs,
140	},
141	Sign {
142		#[clap(flatten)]
143		app_path: AppPathArgs,
144	},
145}
146
147#[derive(Subcommand, Debug)]
148pub enum Spctl {
149	AssessApp {
150		#[clap(flatten)]
151		app_path: AppPathArgs,
152	},
153}
154
155#[derive(Subcommand, Debug)]
156pub enum XcRun {
157	#[clap(subcommand)]
158	Simctl(Simctl),
159}
160
161#[derive(Debug, ValueEnum, Clone)]
162pub enum Booted {
163	Booted,
164}
165
166#[derive(Subcommand, Debug)]
167pub enum Simctl {
168	List,
169	Boot {
170		#[clap(flatten)]
171		simulator_id: DeviceSimulatorUnBootedArgs,
172	},
173	Install {
174		#[clap(flatten)]
175		booted_simulator: DeviceSimulatorBootedArgs,
176
177		#[clap(flatten)]
178		app_path: app_path::AppPathArgs,
179	},
180	Launch {
181		#[clap(flatten)]
182		booted_simulator: DeviceSimulatorBootedArgs,
183
184		#[clap(flatten)]
185		args: simctl::launch::CliLaunchArgs,
186	},
187}
188
189#[derive(Args, Debug)]
190pub struct Open {
191	#[arg(long, value_enum)]
192	pub well_known: WellKnown,
193}