Skip to content

Commit

Permalink
feat(core): add App::get_cli_matches helper ref #4145
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 17, 2022
1 parent 612c734 commit 617f114
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/add-app-get-matches-helper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Added the `App::get_cli_matches` helper function.
4 changes: 2 additions & 2 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions core/tauri/src/api/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/endpoints/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 617f114

Please sign in to comment.