Skip to content

Commit

Permalink
feat(cli/plugin): add --no-example flag
Browse files Browse the repository at this point in the history
closes #11009
  • Loading branch information
amrbashir committed Sep 16, 2024
1 parent 551e062 commit 824a82a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changes/cli-plugin-no-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-cli": "patch:feat"
"@tauri-apps/cli": "patch:feat"
---

Add `--no-example` flag for `tauri plugin new` and `tauri plugin init` to disable creation of an example project.

20 changes: 12 additions & 8 deletions crates/tauri-cli/src/plugin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ pub struct Options {
/// Initializes a Tauri plugin without the TypeScript API
#[clap(long)]
pub(crate) no_api: bool,
/// Initializes a Tauri core plugin (internal usage)
#[clap(long, hide(true))]
pub(crate) tauri: bool,
/// Initialize without an example project.
#[clap(long)]
pub(crate) no_example: bool,
/// Set target directory for init
#[clap(short, long)]
#[clap(default_value_t = current_dir().expect("failed to read cwd").display().to_string())]
pub(crate) directory: String,
/// Path of the Tauri project to use (relative to the cwd)
#[clap(short, long)]
pub(crate) tauri_path: Option<PathBuf>,
/// Author name
#[clap(short, long)]
pub(crate) author: Option<String>,
Expand All @@ -59,6 +56,13 @@ pub struct Options {
#[clap(long)]
#[clap(default_value_t = PluginIosFramework::default())]
pub(crate) ios_framework: PluginIosFramework,

/// Initializes a Tauri core plugin (internal usage)
#[clap(long, hide(true))]
pub(crate) tauri: bool,
/// Path of the Tauri project to use (relative to the cwd)
#[clap(short, long)]
pub(crate) tauri_path: Option<PathBuf>,
}

impl Options {
Expand Down Expand Up @@ -176,14 +180,14 @@ pub fn command(mut options: Options) -> Result<()> {
if let Component::Normal(component) = root {
match component.to_str().unwrap() {
"__example-api" => {
if options.no_api {
if options.no_api || options.no_example {
return Ok(None);
} else {
path = Path::new("examples").join(components.collect::<PathBuf>());
}
}
"__example-basic" => {
if options.no_api {
if options.no_api && !options.no_example {
path = Path::new("examples").join(components.collect::<PathBuf>());
} else {
return Ok(None);
Expand Down
22 changes: 14 additions & 8 deletions crates/tauri-cli/src/plugin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ pub struct Options {
/// Initializes a Tauri plugin without the TypeScript API
#[clap(long)]
no_api: bool,
/// Initializes a Tauri core plugin (internal usage)
#[clap(long, hide(true))]
tauri: bool,
/// Initialize without an example project.
#[clap(long)]
no_example: bool,
/// Set target directory for init
#[clap(short, long)]
directory: Option<String>,
/// Path of the Tauri project to use (relative to the cwd)
#[clap(short, long)]
tauri_path: Option<PathBuf>,
/// Author name
#[clap(short, long)]
author: Option<String>,
Expand All @@ -40,21 +37,30 @@ pub struct Options {
#[clap(long)]
#[clap(default_value_t = PluginIosFramework::default())]
pub(crate) ios_framework: PluginIosFramework,

/// Initializes a Tauri core plugin (internal usage)
#[clap(long, hide(true))]
tauri: bool,
/// Path of the Tauri project to use (relative to the cwd)
#[clap(short, long)]
tauri_path: Option<PathBuf>,
}

impl From<Options> for super::init::Options {
fn from(o: Options) -> Self {
Self {
plugin_name: Some(o.plugin_name),
no_api: o.no_api,
tauri: o.tauri,
no_example: o.no_example,
directory: o.directory.unwrap(),
tauri_path: o.tauri_path,
author: o.author,
android: o.android,
ios: o.ios,
mobile: o.mobile,
ios_framework: o.ios_framework,

tauri: o.tauri,
tauri_path: o.tauri_path,
}
}
}
Expand Down

0 comments on commit 824a82a

Please sign in to comment.