feat(core): add App::get_cli_matches helper ref #4145

This commit is contained in:
Lucas Nogueira
2022-05-17 18:10:38 -03:00
parent 612c7341e5
commit 617f1144f3
5 changed files with 31 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri": patch
---
Added the `App::get_cli_matches` helper function.

View File

@@ -2237,12 +2237,12 @@ impl PackageConfig {
/// [`tauri init`](https://tauri.studio/v1/api/cli#init) command that lives in
/// your Tauri application source directory (src-tauri). Once generated, you may
/// modify it at will to customize your Tauri application.
///
///
/// In addition to the JSON defined on the `tauri.conf.json` file, Tauri can
/// read a platform-specific configuration from `tauri.linux.conf.json`,
/// `tauri.windows.conf.json`, and `tauri.macos.conf.json` and merges it with
/// the main `tauri.conf.json` configuration.
///
///
/// ```json title="Example tauri.config.json file"
/// {
/// "build": {

View File

@@ -84,6 +84,9 @@ impl Matches {
/// Gets the argument matches of the CLI definition.
///
/// This is a low level API. If the application has been built,
/// prefer [`App::get_cli_matches`](`crate::App#method.get_cli_matches`).
///
/// # Examples
///
/// ```rust,no_run

View File

@@ -630,6 +630,26 @@ impl<R: Runtime> App<R> {
.set_activation_policy(activation_policy);
}
/// Gets the argument matches of the CLI definition configured in `tauri.conf.json`.
///
/// # Examples
///
/// ```rust,no_run
/// tauri::Builder::default()
/// .setup(|app| {
/// let matches = app.get_cli_matches()?;
/// Ok(())
/// });
/// ```
#[cfg(cli)]
pub fn get_cli_matches(&self) -> crate::Result<crate::api::cli::Matches> {
if let Some(cli) = &self.manager.config().tauri.cli {
crate::api::cli::get_matches(cli, self.manager.package_info()).map_err(Into::into)
} else {
Ok(Default::default())
}
}
/// Runs the application.
///
/// # Examples

View File

@@ -26,7 +26,7 @@ impl Cmd {
.map(Into::into)
.map_err(Into::into)
} else {
Err(crate::error::into_anyhow("CLI definition not set under tauri.conf.json > tauri > cli (https://tauri.studio/docs/api/config#tauri.cli)"))
Ok(crate::api::cli::Matches::default().into())
}
}