swift_bridge_cli/
clap_app.rs

1use clap::{Arg, ArgAction, Command};
2
3/// The CLI application
4pub fn cli() -> Command<'static> {
5    Command::new("swift-bridge")
6        .about("facilitates Rust and Swift interop.")
7        .version(env!("CARGO_PKG_VERSION"))
8        .subcommand_required(true)
9        .subcommand(create_package_command())
10        .subcommand(create_bridges_command())
11}
12
13/// The command for creating a Swift Package
14fn create_package_command() -> Command<'static> {
15    Command::new("create-package")
16        .about("Create a Swift Package from Rust code.")
17        .arg(
18            Arg::new("bridges-dir")
19                .long("bridges-dir")
20                .takes_value(true)
21                .value_name("PATH")
22                .required(true)
23                .help("The path to the generated bridge files"),
24        )
25        .arg(
26            Arg::new("ios")
27                .long("ios")
28                .takes_value(true)
29                .value_name("PATH")
30                .help("The path to the compiled Rust library for iOS"),
31        )
32        .arg(
33            Arg::new("simulator")
34                .long("simulator")
35                .takes_value(true)
36                .value_name("PATH")
37                .help("The path to the compiled Rust library for the iOS Simulator"),
38        )
39        .arg(
40            Arg::new("macos")
41                .long("macos")
42                .takes_value(true)
43                .value_name("PATH")
44                .help("The path to the compiled Rust library for MacOS"),
45        )
46        .arg(
47            Arg::new("mac-catalyst")
48                .long("mac-catalyst")
49                .takes_value(true)
50                .value_name("PATH")
51                .help("The path to the compiled Rust library for MacCatalyst"),
52        )
53        .arg(
54            Arg::new("tvos")
55                .long("tvos")
56                .takes_value(true)
57                .value_name("PATH")
58                .help("The path to the compiled Rust library for tvOS"),
59        )
60        .arg(
61            Arg::new("watchos")
62                .long("watchos")
63                .takes_value(true)
64                .value_name("PATH")
65                .help("The path to the compiled Rust library for WatchOS"),
66        )
67        .arg(
68            Arg::new("watchos-simulator")
69                .long("watchos-simulator")
70                .takes_value(true)
71                .value_name("PATH")
72                .help("The path to the compiled Rust library for WatchOSSimulator"),
73        )
74        .arg(
75            Arg::new("carplay")
76                .long("carplay")
77                .takes_value(true)
78                .value_name("PATH")
79                .help("The path to the compiled Rust library for AppleCarplay"),
80        )
81        .arg(
82            Arg::new("carplay-simulator")
83                .long("carplay-simulator")
84                .takes_value(true)
85                .value_name("PATH")
86                .help("The path to the compiled Rust library for AppleCarplaySimulator"),
87        )
88        .arg(
89            Arg::new("out-dir")
90                .long("out-dir")
91                .takes_value(true)
92                .value_name("PATH")
93                .required(true)
94                .help("The path of the Swift Package"),
95        )
96        .arg(
97            Arg::new("name")
98                .long("name")
99                .takes_value(true)
100                .value_name("PATH")
101                .required(true)
102                .help("The name for the Swift Package"),
103        )
104}
105
106fn create_bridges_command() -> Command<'static> {
107    Command::new("parse-bridges")
108        .about("Parse bridge library files and output generated headers")
109        .arg(
110            Arg::new("crate-name")
111                .action(ArgAction::Set)
112                .help(
113                    "Crate name for which the bridging headers are generated; \
114                          used as a part of header names",
115                )
116                .long("--crate-name")
117                .required(true),
118        )
119        .arg(
120            Arg::new("source-file")
121                .action(ArgAction::Append)
122                .help("source file(s) containing #[swift_bridge::bridge] macro")
123                .long("file")
124                .short('f')
125                .required(true),
126        )
127        .arg(
128            Arg::new("output")
129                .action(ArgAction::Set)
130                .help("Output destination folder")
131                .long("output")
132                .short('o')
133                .value_name("PATH")
134                .required(true),
135        )
136}