Skip to content

Commit 617f114

Browse files
committed
feat(core): add App::get_cli_matches helper ref #4145
1 parent 612c734 commit 617f114

5 files changed

Lines changed: 31 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Added the `App::get_cli_matches` helper function.

core/tauri-utils/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,12 +2237,12 @@ impl PackageConfig {
22372237
/// [`tauri init`](https://tauri.studio/v1/api/cli#init) command that lives in
22382238
/// your Tauri application source directory (src-tauri). Once generated, you may
22392239
/// modify it at will to customize your Tauri application.
2240-
///
2240+
///
22412241
/// In addition to the JSON defined on the `tauri.conf.json` file, Tauri can
22422242
/// read a platform-specific configuration from `tauri.linux.conf.json`,
22432243
/// `tauri.windows.conf.json`, and `tauri.macos.conf.json` and merges it with
22442244
/// the main `tauri.conf.json` configuration.
2245-
///
2245+
///
22462246
/// ```json title="Example tauri.config.json file"
22472247
/// {
22482248
/// "build": {

core/tauri/src/api/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ impl Matches {
8484

8585
/// Gets the argument matches of the CLI definition.
8686
///
87+
/// This is a low level API. If the application has been built,
88+
/// prefer [`App::get_cli_matches`](`crate::App#method.get_cli_matches`).
89+
///
8790
/// # Examples
8891
///
8992
/// ```rust,no_run

core/tauri/src/app.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,26 @@ impl<R: Runtime> App<R> {
630630
.set_activation_policy(activation_policy);
631631
}
632632

633+
/// Gets the argument matches of the CLI definition configured in `tauri.conf.json`.
634+
///
635+
/// # Examples
636+
///
637+
/// ```rust,no_run
638+
/// tauri::Builder::default()
639+
/// .setup(|app| {
640+
/// let matches = app.get_cli_matches()?;
641+
/// Ok(())
642+
/// });
643+
/// ```
644+
#[cfg(cli)]
645+
pub fn get_cli_matches(&self) -> crate::Result<crate::api::cli::Matches> {
646+
if let Some(cli) = &self.manager.config().tauri.cli {
647+
crate::api::cli::get_matches(cli, self.manager.package_info()).map_err(Into::into)
648+
} else {
649+
Ok(Default::default())
650+
}
651+
}
652+
633653
/// Runs the application.
634654
///
635655
/// # Examples

core/tauri/src/endpoints/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Cmd {
2626
.map(Into::into)
2727
.map_err(Into::into)
2828
} else {
29-
Err(crate::error::into_anyhow("CLI definition not set under tauri.conf.json > tauri > cli (https://tauri.studio/docs/api/config#tauri.cli)"))
29+
Ok(crate::api::cli::Matches::default().into())
3030
}
3131
}
3232

0 commit comments

Comments
 (0)