Skip to content

Commit

Permalink
refactor(cli.rs): rename init plugin subcommand to plugin init (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Nov 13, 2021
1 parent dfe508d commit db275f0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .changes/plugin-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
65 changes: 33 additions & 32 deletions tooling/cli.rs/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
76 changes: 39 additions & 37 deletions tooling/cli.rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
});

let mut plugin_runner = plugin::Plugin::new()
.plugin_name(plugin_name.to_string())
.author(author);
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);

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()
} else {
Ok(())
}

plugin_runner.run()
}

fn init_command(matches: &ArgMatches) -> Result<()> {
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit db275f0

Please sign in to comment.