Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/add-optional-args-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli": minor
---

Added `tauri_plugin_cli::matches_from`. This can be combined with the `args` passed to the callback of `tauri_plugin_single_instance` to parse the command line arguments passed to subsequent instances of the application.
6 changes: 5 additions & 1 deletion plugins/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ pub struct Cli<R: Runtime>(PluginApi<R, Config>);

impl<R: Runtime> Cli<R> {
pub fn matches(&self) -> Result<parser::Matches> {
parser::get_matches(self.0.config(), self.0.app().package_info())
parser::get_matches(self.0.config(), self.0.app().package_info(), None)
}

pub fn matches_from(&self, args: Vec<String>) -> Result<parser::Matches> {
parser::get_matches(self.0.config(), self.0.app().package_info(), Some(args))
}
}

Expand Down
15 changes: 13 additions & 2 deletions plugins/cli/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ impl Matches {
/// Ok(())
/// });
/// ```
pub fn get_matches(cli: &Config, package_info: &PackageInfo) -> crate::Result<Matches> {
pub fn get_matches(
cli: &Config,
package_info: &PackageInfo,
args: Option<Vec<String>>,
) -> crate::Result<Matches> {
Comment on lines +82 to +86
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Legend-Master Curious and slightly bored here, hope you don't mind me asking. You called out the changes to Cli.matches as a breaking change, how is this also not considered a breaking change? Both Cli.matches and parser::get_matches are public, and neither are referenced anywhere in the usage guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, did not notice that the docs do mention Cli.matches.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser is a private module, so parser::get_matches is not actually public, yeah I know it's kinda confusing 😂

let about = cli
.description()
.unwrap_or(&package_info.description.to_string())
Expand All @@ -92,7 +96,14 @@ pub fn get_matches(cli: &Config, package_info: &PackageInfo) -> crate::Result<Ma
Some(&about),
cli,
);
match app.try_get_matches() {

let matches = if let Some(args) = args {
app.try_get_matches_from(args)
} else {
app.try_get_matches()
};

match matches {
Ok(matches) => Ok(get_matches_internal(cli, &matches)),
Err(e) => match e.kind() {
ErrorKind::DisplayHelp => {
Expand Down
Loading