mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): add App::get_cli_matches helper ref #4145
This commit is contained in:
5
.changes/add-app-get-matches-helper.md
Normal file
5
.changes/add-app-get-matches-helper.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Added the `App::get_cli_matches` helper function.
|
||||
@@ -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": {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user