Skip to content

Commit 9bb8fc6

Browse files
authored
feat(cli/plugin): add --no-example flag (#11030)
closes #11009
1 parent 551e062 commit 9bb8fc6

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

.changes/cli-plugin-no-example.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-cli": "patch:feat"
3+
"@tauri-apps/cli": "patch:feat"
4+
---
5+
6+
Add `--no-example` flag for `tauri plugin new` and `tauri plugin init` to disable creation of an example project.
7+

crates/tauri-cli/src/plugin/init.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ pub struct Options {
3333
/// Initializes a Tauri plugin without the TypeScript API
3434
#[clap(long)]
3535
pub(crate) no_api: bool,
36-
/// Initializes a Tauri core plugin (internal usage)
37-
#[clap(long, hide(true))]
38-
pub(crate) tauri: bool,
36+
/// Initialize without an example project.
37+
#[clap(long)]
38+
pub(crate) no_example: bool,
3939
/// Set target directory for init
4040
#[clap(short, long)]
4141
#[clap(default_value_t = current_dir().expect("failed to read cwd").display().to_string())]
4242
pub(crate) directory: String,
43-
/// Path of the Tauri project to use (relative to the cwd)
44-
#[clap(short, long)]
45-
pub(crate) tauri_path: Option<PathBuf>,
4643
/// Author name
4744
#[clap(short, long)]
4845
pub(crate) author: Option<String>,
@@ -59,6 +56,13 @@ pub struct Options {
5956
#[clap(long)]
6057
#[clap(default_value_t = PluginIosFramework::default())]
6158
pub(crate) ios_framework: PluginIosFramework,
59+
60+
/// Initializes a Tauri core plugin (internal usage)
61+
#[clap(long, hide(true))]
62+
pub(crate) tauri: bool,
63+
/// Path of the Tauri project to use (relative to the cwd)
64+
#[clap(short, long)]
65+
pub(crate) tauri_path: Option<PathBuf>,
6266
}
6367

6468
impl Options {
@@ -176,14 +180,14 @@ pub fn command(mut options: Options) -> Result<()> {
176180
if let Component::Normal(component) = root {
177181
match component.to_str().unwrap() {
178182
"__example-api" => {
179-
if options.no_api {
183+
if options.no_api || options.no_example {
180184
return Ok(None);
181185
} else {
182186
path = Path::new("examples").join(components.collect::<PathBuf>());
183187
}
184188
}
185189
"__example-basic" => {
186-
if options.no_api {
190+
if options.no_api && !options.no_example {
187191
path = Path::new("examples").join(components.collect::<PathBuf>());
188192
} else {
189193
return Ok(None);

crates/tauri-cli/src/plugin/new.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ pub struct Options {
1515
/// Initializes a Tauri plugin without the TypeScript API
1616
#[clap(long)]
1717
no_api: bool,
18-
/// Initializes a Tauri core plugin (internal usage)
19-
#[clap(long, hide(true))]
20-
tauri: bool,
18+
/// Initialize without an example project.
19+
#[clap(long)]
20+
no_example: bool,
2121
/// Set target directory for init
2222
#[clap(short, long)]
2323
directory: Option<String>,
24-
/// Path of the Tauri project to use (relative to the cwd)
25-
#[clap(short, long)]
26-
tauri_path: Option<PathBuf>,
2724
/// Author name
2825
#[clap(short, long)]
2926
author: Option<String>,
@@ -40,21 +37,30 @@ pub struct Options {
4037
#[clap(long)]
4138
#[clap(default_value_t = PluginIosFramework::default())]
4239
pub(crate) ios_framework: PluginIosFramework,
40+
41+
/// Initializes a Tauri core plugin (internal usage)
42+
#[clap(long, hide(true))]
43+
tauri: bool,
44+
/// Path of the Tauri project to use (relative to the cwd)
45+
#[clap(short, long)]
46+
tauri_path: Option<PathBuf>,
4347
}
4448

4549
impl From<Options> for super::init::Options {
4650
fn from(o: Options) -> Self {
4751
Self {
4852
plugin_name: Some(o.plugin_name),
4953
no_api: o.no_api,
50-
tauri: o.tauri,
54+
no_example: o.no_example,
5155
directory: o.directory.unwrap(),
52-
tauri_path: o.tauri_path,
5356
author: o.author,
5457
android: o.android,
5558
ios: o.ios,
5659
mobile: o.mobile,
5760
ios_framework: o.ios_framework,
61+
62+
tauri: o.tauri,
63+
tauri_path: o.tauri_path,
5864
}
5965
}
6066
}

0 commit comments

Comments
 (0)