From db275f0b633f44fb2f85755d32929dfb7893b1e0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 13 Nov 2021 19:28:18 -0300 Subject: [PATCH] refactor(cli.rs): rename `init plugin` subcommand to `plugin init` (#2885) --- .changes/plugin-command.md | 2 +- tooling/cli.rs/src/cli.yml | 65 ++++++++++++++++----------------- tooling/cli.rs/src/main.rs | 74 +++++++++++++++++++------------------- 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/.changes/plugin-command.md b/.changes/plugin-command.md index 9028ea4b8..865b5af03 100644 --- a/.changes/plugin-command.md +++ b/.changes/plugin-command.md @@ -2,4 +2,4 @@ "cli.rs": patch --- -Added `$ tauri init plugin` command, which initializes a Tauri plugin. +Added `$ tauri plugin init` command, which initializes a Tauri plugin. diff --git a/tooling/cli.rs/src/cli.yml b/tooling/cli.rs/src/cli.yml index 76d0032ac..4f249176f 100644 --- a/tooling/cli.rs/src/cli.yml +++ b/tooling/cli.rs/src/cli.yml @@ -124,7 +124,6 @@ subcommands: long: force about: Overwrite private key even if it exists on the specified path requires: generate - - info: about: Shows information about Tauri dependencies - init: @@ -171,35 +170,37 @@ subcommands: long: dev-path about: Url of your dev server takes_value: true + - plugin: + about: Manage Tauri plugins. subcommands: - - plugin: - about: Initializes a Tauri plugin project. - args: - - name: - short: n - long: name - about: Name of your Tauri plugin - takes_value: true - required: true - - directory: - short: d - long: directory - about: Set target directory for init - takes_value: true - - tauri-path: - short: t - long: tauri-path - about: Path of the Tauri project to use (relative to the cwd) - takes_value: true - - api: - short: a - long: api - about: Initializes a Tauri plugin with TypeScript API. - - author: - long: author - about: Author name. - takes_value: true - - tauri: - long: tauri - about: Initializes a Tauri core plugin (internal usage). - setting: Hidden + - init: + about: Initializes a Tauri plugin project. + args: + - name: + short: n + long: name + about: Name of your Tauri plugin + takes_value: true + required: true + - directory: + short: d + long: directory + about: Set target directory for init + takes_value: true + - tauri-path: + short: t + long: tauri-path + about: Path of the Tauri project to use (relative to the cwd) + takes_value: true + - api: + short: a + long: api + about: Initializes a Tauri plugin with TypeScript API. + - author: + long: author + about: Author name. + takes_value: true + - tauri: + long: tauri + about: Initializes a Tauri core plugin (internal usage). + setting: Hidden diff --git a/tooling/cli.rs/src/main.rs b/tooling/cli.rs/src/main.rs index 1a3bd56aa..99fb4ca6c 100644 --- a/tooling/cli.rs/src/main.rs +++ b/tooling/cli.rs/src/main.rs @@ -58,40 +58,44 @@ macro_rules! value_or_prompt { } fn plugin_command(matches: &ArgMatches) -> Result<()> { - let api = matches.is_present("api"); - let plugin_name = matches.value_of("name").expect("name is required"); - let directory = matches.value_of("directory"); - let tauri_path = matches.value_of("tauri-path"); - let tauri = matches.is_present("tauri"); - let author = matches - .value_of("author") - .map(|p| p.to_string()) - .unwrap_or_else(|| { - if tauri { - "Tauri Programme within The Commons Conservancy".into() - } else { - "You".into() - } - }); + if let Some(matches) = matches.subcommand_matches("init") { + let api = matches.is_present("api"); + let plugin_name = matches.value_of("name").expect("name is required"); + let directory = matches.value_of("directory"); + let tauri_path = matches.value_of("tauri-path"); + let tauri = matches.is_present("tauri"); + let author = matches + .value_of("author") + .map(|p| p.to_string()) + .unwrap_or_else(|| { + if tauri { + "Tauri Programme within The Commons Conservancy".into() + } else { + "You".into() + } + }); - let mut plugin_runner = plugin::Plugin::new() - .plugin_name(plugin_name.to_string()) - .author(author); + let mut plugin_runner = plugin::Plugin::new() + .plugin_name(plugin_name.to_string()) + .author(author); - if api { - plugin_runner = plugin_runner.api(); - } - if tauri { - plugin_runner = plugin_runner.tauri(); - } - if let Some(directory) = directory { - plugin_runner = plugin_runner.directory(directory); - } - if let Some(tauri_path) = tauri_path { - plugin_runner = plugin_runner.tauri_path(tauri_path); - } + if api { + plugin_runner = plugin_runner.api(); + } + if tauri { + plugin_runner = plugin_runner.tauri(); + } + if let Some(directory) = directory { + plugin_runner = plugin_runner.directory(directory); + } + if let Some(tauri_path) = tauri_path { + plugin_runner = plugin_runner.tauri_path(tauri_path); + } - plugin_runner.run() + plugin_runner.run() + } else { + Ok(()) + } } fn init_command(matches: &ArgMatches) -> Result<()> { @@ -308,11 +312,9 @@ fn main() -> Result<()> { let matches = app.get_matches(); if let Some(matches) = matches.subcommand_matches("init") { - if let Some(matches) = matches.subcommand_matches("plugin") { - plugin_command(matches)?; - } else { - init_command(matches)?; - } + init_command(matches)?; + } else if let Some(matches) = matches.subcommand_matches("plugin") { + plugin_command(matches)?; } else if let Some(matches) = matches.subcommand_matches("dev") { dev_command(matches)?; } else if let Some(matches) = matches.subcommand_matches("build") {