-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
main.rs
232 lines (200 loc) · 6.37 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
pub use anyhow::Result;
use clap::{crate_version, load_yaml, App, AppSettings, ArgMatches};
use dialoguer::Input;
mod build;
mod dev;
mod helpers;
mod info;
mod init;
mod sign;
// temporary fork from https://github.com/mitsuhiko/console until 0.14.1+ release
#[allow(dead_code)]
mod console;
// temporary fork from https://github.com/mitsuhiko/dialoguer until 0.8.0+ release
#[allow(dead_code)]
mod dialoguer;
pub use helpers::Logger;
macro_rules! value_or_prompt {
($init_runner: ident, $setter_fn: ident, $value: ident, $ci: ident, $prompt_message: expr) => {{
let mut init_runner = $init_runner;
if let Some(value) = $value {
init_runner = init_runner.$setter_fn(value);
} else if !$ci {
let input = Input::<String>::new()
.with_prompt($prompt_message)
.interact_text()?;
init_runner = init_runner.$setter_fn(input);
}
init_runner
}};
}
fn init_command(matches: &ArgMatches) -> Result<()> {
let force = matches.is_present("force");
let directory = matches.value_of("directory");
let tauri_path = matches.value_of("tauri-path");
let app_name = matches.value_of("app-name");
let window_title = matches.value_of("window-title");
let dist_dir = matches.value_of("dist-dir");
let dev_path = matches.value_of("dev-path");
let ci = matches.is_present("ci") || std::env::var("CI").is_ok();
let mut init_runner = init::Init::new();
if force {
init_runner = init_runner.force();
}
if let Some(directory) = directory {
init_runner = init_runner.directory(directory);
}
if let Some(tauri_path) = tauri_path {
init_runner = init_runner.tauri_path(tauri_path);
}
init_runner = value_or_prompt!(
init_runner,
app_name,
app_name,
ci,
"What is your app name?"
);
init_runner = value_or_prompt!(
init_runner,
window_title,
window_title,
ci,
"What should the window title be?"
);
init_runner = value_or_prompt!(
init_runner,
dist_dir,
dist_dir,
ci,
r#"Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri" folder that will be created?"#
);
init_runner = value_or_prompt!(
init_runner,
dev_path,
dev_path,
ci,
"What is the url of your dev server?"
);
init_runner.run()
}
fn dev_command(matches: &ArgMatches) -> Result<()> {
let runner = matches.value_of("runner");
let target = matches.value_of("target");
let exit_on_panic = matches.is_present("exit-on-panic");
let config = matches.value_of("config");
let args: Vec<String> = matches
.values_of("args")
.map(|a| a.into_iter().map(|v| v.to_string()).collect())
.unwrap_or_default();
let mut dev_runner = dev::Dev::new().exit_on_panic(exit_on_panic).args(args);
if let Some(runner) = runner {
dev_runner = dev_runner.runner(runner.to_string());
}
if let Some(target) = target {
dev_runner = dev_runner.target(target.to_string());
}
if let Some(config) = config {
dev_runner = dev_runner.config(config.to_string());
}
dev_runner.run()
}
fn build_command(matches: &ArgMatches) -> Result<()> {
let runner = matches.value_of("runner");
let target = matches.value_of("target");
let debug = matches.is_present("debug");
let verbose = matches.is_present("verbose");
let bundles = matches.values_of_lossy("bundle");
let config = matches.value_of("config");
let mut build_runner = build::Build::new();
if let Some(runner) = runner {
build_runner = build_runner.runner(runner.to_string());
}
if let Some(target) = target {
build_runner = build_runner.target(target.to_string());
}
if debug {
build_runner = build_runner.debug();
}
if verbose {
build_runner = build_runner.verbose();
}
if let Some(bundles) = bundles {
build_runner = build_runner.bundles(bundles);
}
if let Some(config) = config {
build_runner = build_runner.config(config.to_string());
}
build_runner.run()
}
fn info_command() -> Result<()> {
info::Info::new().run()
}
fn sign_command(matches: &ArgMatches) -> Result<()> {
let private_key = matches.value_of("private-key");
let private_key_path = matches.value_of("private-key-path");
let file = matches.value_of("sign-file");
let password = matches.value_of("password");
let no_password = matches.is_present("no-password");
let write_keys = matches.value_of("write-keys");
let force = matches.is_present("force");
// generate keypair
if matches.is_present("generate") {
let mut keygen_runner = sign::KeyGenerator::new();
if no_password {
keygen_runner = keygen_runner.empty_password();
}
if force {
keygen_runner = keygen_runner.force();
}
if let Some(write_keys) = write_keys {
keygen_runner = keygen_runner.output_path(write_keys);
}
if let Some(password) = password {
keygen_runner = keygen_runner.password(password);
}
return keygen_runner.generate_keys();
}
// sign our binary / archive
let mut sign_runner = sign::Signer::new();
if let Some(private_key) = private_key {
sign_runner = sign_runner.private_key(private_key);
}
if let Some(private_key_path) = private_key_path {
sign_runner = sign_runner.private_key_path(private_key_path);
}
if let Some(file) = file {
sign_runner = sign_runner.file_to_sign(file);
}
if let Some(password) = password {
sign_runner = sign_runner.password(password);
}
if no_password {
sign_runner = sign_runner.empty_password();
}
sign_runner.run()
}
fn main() -> Result<()> {
let yaml = load_yaml!("cli.yml");
let app = App::from(yaml)
.version(crate_version!())
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::GlobalVersion)
.setting(AppSettings::SubcommandRequired);
let app_matches = app.get_matches();
let matches = app_matches.subcommand_matches("tauri").unwrap();
if let Some(matches) = matches.subcommand_matches("init") {
init_command(&matches)?;
} else if let Some(matches) = matches.subcommand_matches("dev") {
dev_command(&matches)?;
} else if let Some(matches) = matches.subcommand_matches("build") {
build_command(&matches)?;
} else if matches.subcommand_matches("info").is_some() {
info_command()?;
} else if let Some(matches) = matches.subcommand_matches("sign") {
sign_command(&matches)?;
}
Ok(())
}