Skip to content

Commit ac76a22

Browse files
authored
feat(cli/init): allow empty responses non-crucial questions (#9183)
closes #9181
1 parent 81b853b commit ac76a22

File tree

6 files changed

+41
-34
lines changed

6 files changed

+41
-34
lines changed

.changes/cli-empty-responses.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-cli': 'patch:enhance'
3+
'@tauri-apps/cli': 'patch:enhance'
4+
---
5+
6+
Allow empty responses for `devUrl`, `beforeDevCommand` and `beforeBuildCommands` questions in `tauri init`.

tooling/cli/src/helpers/prompts.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn input<T>(
1515
where
1616
T: Clone + FromStr + Display + ToString,
1717
T::Err: Display + std::fmt::Debug,
18+
T: PartialEq<str>,
1819
{
1920
if skip {
2021
Ok(initial)
@@ -28,7 +29,10 @@ where
2829
builder = builder.with_initial_text(v.to_string());
2930
}
3031

31-
builder.interact_text().map(Some).map_err(Into::into)
32+
builder
33+
.interact_text()
34+
.map(|t: T| if t.ne("") { Some(t) } else { None })
35+
.map_err(Into::into)
3236
}
3337
}
3438

tooling/cli/src/init.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,28 @@ impl Options {
8989
self.app_name = self.app_name.map(|s| Ok(Some(s))).unwrap_or_else(|| {
9090
prompts::input(
9191
"What is your app name?",
92-
init_defaults.app_name.clone(),
92+
Some(
93+
init_defaults
94+
.app_name
95+
.clone()
96+
.unwrap_or_else(|| "Tauri App".to_string()),
97+
),
9398
self.ci,
94-
false,
99+
true,
95100
)
96101
})?;
97102

98103
self.window_title = self.window_title.map(|s| Ok(Some(s))).unwrap_or_else(|| {
99104
prompts::input(
100105
"What should the window title be?",
101-
init_defaults.app_name.clone(),
106+
Some(
107+
init_defaults
108+
.app_name
109+
.clone()
110+
.unwrap_or_else(|| "Tauri".to_string()),
111+
),
102112
self.ci,
103-
false,
113+
true,
104114
)
105115
})?;
106116

@@ -116,7 +126,7 @@ impl Options {
116126
"What is the url of your dev server?",
117127
init_defaults.framework.map(|f| f.dev_url()),
118128
self.ci,
119-
false,
129+
true,
120130
)
121131
})?;
122132

@@ -131,6 +141,7 @@ impl Options {
131141
true,
132142
)
133143
})?;
144+
134145
self.before_build_command = self
135146
.before_build_command
136147
.map(|s| Ok(Some(s)))
@@ -186,35 +197,21 @@ pub fn command(mut options: Options) -> Result<()> {
186197
data.insert("tauri_build_dep", to_json(tauri_build_dep));
187198
data.insert(
188199
"frontend_dist",
189-
to_json(
190-
options
191-
.frontend_dist
192-
.unwrap_or_else(|| "../dist".to_string()),
193-
),
194-
);
195-
data.insert(
196-
"dev_url",
197-
to_json(
198-
options
199-
.dev_url
200-
.unwrap_or_else(|| "http://localhost:4000".to_string()),
201-
),
200+
to_json(options.frontend_dist.as_deref().unwrap_or("../dist")),
202201
);
202+
data.insert("dev_url", to_json(options.dev_url));
203203
data.insert(
204204
"app_name",
205-
to_json(options.app_name.unwrap_or_else(|| "Tauri App".to_string())),
205+
to_json(options.app_name.as_deref().unwrap_or("Tauri App")),
206206
);
207207
data.insert(
208208
"window_title",
209-
to_json(options.window_title.unwrap_or_else(|| "Tauri".to_string())),
210-
);
211-
data.insert(
212-
"before_dev_command",
213-
to_json(options.before_dev_command.unwrap_or_default()),
209+
to_json(options.window_title.as_deref().unwrap_or("Tauri")),
214210
);
211+
data.insert("before_dev_command", to_json(options.before_dev_command));
215212
data.insert(
216213
"before_build_command",
217-
to_json(options.before_build_command.unwrap_or_default()),
214+
to_json(options.before_build_command),
218215
);
219216

220217
let mut config = serde_json::from_str(

tooling/cli/src/plugin/android.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: MIT
44

55
use crate::{
6-
helpers::{prompts::input, template},
6+
helpers::{prompts, template},
77
Result,
88
};
99
use clap::{Parser, Subcommand};
@@ -59,7 +59,7 @@ pub fn command(cli: Cli) -> Result<()> {
5959
return Err(anyhow::anyhow!("android folder already exists"));
6060
}
6161

62-
let plugin_id = input(
62+
let plugin_id = prompts::input(
6363
"What should be the Android Package ID for your plugin?",
6464
Some(format!("com.plugin.{}", plugin_name)),
6565
false,

tooling/cli/src/plugin/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use crate::helpers::prompts::input;
5+
use crate::helpers::prompts;
66
use crate::Result;
77
use crate::{
88
helpers::{resolve_tauri_path, template},
@@ -141,7 +141,7 @@ pub fn command(mut options: Options) -> Result<()> {
141141
}
142142

143143
let plugin_id = if options.android || options.mobile {
144-
let plugin_id = input(
144+
let plugin_id = prompts::input(
145145
"What should be the Android Package ID for your plugin?",
146146
Some(format!("com.plugin.{}", plugin_name)),
147147
false,

tooling/cli/templates/tauri.conf.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.1.0",
44
"identifier": "com.tauri.dev",
55
"build": {
6-
"frontendDist": "{{ frontend_dist }}",
7-
"devUrl": "{{ dev_url }}",
8-
"beforeDevCommand": "{{ before_dev_command }}",
9-
"beforeBuildCommand": "{{ before_build_command }}"
6+
"frontendDist": "{{ frontend_dist }}"{{#if dev_url}},
7+
"devUrl": "{{ dev_url }}"{{/if}}{{#if before_dev_command}},
8+
"beforeDevCommand": "{{ before_dev_command }}"{{/if}}{{#if before_build_command}},
9+
"beforeBuildCommand": "{{ before_build_command }}"{{/if}}
1010
},
1111
"app": {
1212
"windows": [

0 commit comments

Comments
 (0)