Skip to content

Commit db275f0

Browse files
authored
refactor(cli.rs): rename init plugin subcommand to plugin init (#2885)
1 parent dfe508d commit db275f0

File tree

3 files changed

+73
-70
lines changed

3 files changed

+73
-70
lines changed

.changes/plugin-command.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"cli.rs": patch
33
---
44

5-
Added `$ tauri init plugin` command, which initializes a Tauri plugin.
5+
Added `$ tauri plugin init` command, which initializes a Tauri plugin.

tooling/cli.rs/src/cli.yml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ subcommands:
124124
long: force
125125
about: Overwrite private key even if it exists on the specified path
126126
requires: generate
127-
128127
- info:
129128
about: Shows information about Tauri dependencies
130129
- init:
@@ -171,35 +170,37 @@ subcommands:
171170
long: dev-path
172171
about: Url of your dev server
173172
takes_value: true
173+
- plugin:
174+
about: Manage Tauri plugins.
174175
subcommands:
175-
- plugin:
176-
about: Initializes a Tauri plugin project.
177-
args:
178-
- name:
179-
short: n
180-
long: name
181-
about: Name of your Tauri plugin
182-
takes_value: true
183-
required: true
184-
- directory:
185-
short: d
186-
long: directory
187-
about: Set target directory for init
188-
takes_value: true
189-
- tauri-path:
190-
short: t
191-
long: tauri-path
192-
about: Path of the Tauri project to use (relative to the cwd)
193-
takes_value: true
194-
- api:
195-
short: a
196-
long: api
197-
about: Initializes a Tauri plugin with TypeScript API.
198-
- author:
199-
long: author
200-
about: Author name.
201-
takes_value: true
202-
- tauri:
203-
long: tauri
204-
about: Initializes a Tauri core plugin (internal usage).
205-
setting: Hidden
176+
- init:
177+
about: Initializes a Tauri plugin project.
178+
args:
179+
- name:
180+
short: n
181+
long: name
182+
about: Name of your Tauri plugin
183+
takes_value: true
184+
required: true
185+
- directory:
186+
short: d
187+
long: directory
188+
about: Set target directory for init
189+
takes_value: true
190+
- tauri-path:
191+
short: t
192+
long: tauri-path
193+
about: Path of the Tauri project to use (relative to the cwd)
194+
takes_value: true
195+
- api:
196+
short: a
197+
long: api
198+
about: Initializes a Tauri plugin with TypeScript API.
199+
- author:
200+
long: author
201+
about: Author name.
202+
takes_value: true
203+
- tauri:
204+
long: tauri
205+
about: Initializes a Tauri core plugin (internal usage).
206+
setting: Hidden

tooling/cli.rs/src/main.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,44 @@ macro_rules! value_or_prompt {
5858
}
5959

6060
fn plugin_command(matches: &ArgMatches) -> Result<()> {
61-
let api = matches.is_present("api");
62-
let plugin_name = matches.value_of("name").expect("name is required");
63-
let directory = matches.value_of("directory");
64-
let tauri_path = matches.value_of("tauri-path");
65-
let tauri = matches.is_present("tauri");
66-
let author = matches
67-
.value_of("author")
68-
.map(|p| p.to_string())
69-
.unwrap_or_else(|| {
70-
if tauri {
71-
"Tauri Programme within The Commons Conservancy".into()
72-
} else {
73-
"You".into()
74-
}
75-
});
76-
77-
let mut plugin_runner = plugin::Plugin::new()
78-
.plugin_name(plugin_name.to_string())
79-
.author(author);
61+
if let Some(matches) = matches.subcommand_matches("init") {
62+
let api = matches.is_present("api");
63+
let plugin_name = matches.value_of("name").expect("name is required");
64+
let directory = matches.value_of("directory");
65+
let tauri_path = matches.value_of("tauri-path");
66+
let tauri = matches.is_present("tauri");
67+
let author = matches
68+
.value_of("author")
69+
.map(|p| p.to_string())
70+
.unwrap_or_else(|| {
71+
if tauri {
72+
"Tauri Programme within The Commons Conservancy".into()
73+
} else {
74+
"You".into()
75+
}
76+
});
77+
78+
let mut plugin_runner = plugin::Plugin::new()
79+
.plugin_name(plugin_name.to_string())
80+
.author(author);
81+
82+
if api {
83+
plugin_runner = plugin_runner.api();
84+
}
85+
if tauri {
86+
plugin_runner = plugin_runner.tauri();
87+
}
88+
if let Some(directory) = directory {
89+
plugin_runner = plugin_runner.directory(directory);
90+
}
91+
if let Some(tauri_path) = tauri_path {
92+
plugin_runner = plugin_runner.tauri_path(tauri_path);
93+
}
8094

81-
if api {
82-
plugin_runner = plugin_runner.api();
83-
}
84-
if tauri {
85-
plugin_runner = plugin_runner.tauri();
86-
}
87-
if let Some(directory) = directory {
88-
plugin_runner = plugin_runner.directory(directory);
89-
}
90-
if let Some(tauri_path) = tauri_path {
91-
plugin_runner = plugin_runner.tauri_path(tauri_path);
95+
plugin_runner.run()
96+
} else {
97+
Ok(())
9298
}
93-
94-
plugin_runner.run()
9599
}
96100

97101
fn init_command(matches: &ArgMatches) -> Result<()> {
@@ -308,11 +312,9 @@ fn main() -> Result<()> {
308312
let matches = app.get_matches();
309313

310314
if let Some(matches) = matches.subcommand_matches("init") {
311-
if let Some(matches) = matches.subcommand_matches("plugin") {
312-
plugin_command(matches)?;
313-
} else {
314-
init_command(matches)?;
315-
}
315+
init_command(matches)?;
316+
} else if let Some(matches) = matches.subcommand_matches("plugin") {
317+
plugin_command(matches)?;
316318
} else if let Some(matches) = matches.subcommand_matches("dev") {
317319
dev_command(matches)?;
318320
} else if let Some(matches) = matches.subcommand_matches("build") {

0 commit comments

Comments
 (0)