mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
Update Rust example in cli.md (#2337)
* Update cli.md Updating the example Rust code with an example graciously provided by @amrbashir . This is also in response to a [docs issue](https://github.com/tauri-apps/tauri/issues/2332) that I had raised earlier. * Update docs/usage/guides/cli.md * Update cli.md * Update cli.md Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
05b9d81ee6
commit
2eed5b5e97
@@ -123,16 +123,25 @@ Its configuration is the same as the root application configuration, with the `d
|
||||
### Rust
|
||||
|
||||
```rust
|
||||
use tauri::cli::get_matches;
|
||||
use tauri::api::cli::get_matches;
|
||||
|
||||
fn main() {
|
||||
match get_matches() {
|
||||
Some(matches) => {
|
||||
// `matches` here is a Struct with { args, subcommand }
|
||||
// where args is the HashMap mapping each arg's name to it's { value, occurrences }
|
||||
// and subcommand is an Option of { name, matches }
|
||||
let context = tauri::generate_context!();
|
||||
let cli_config = context.config().tauri.cli.clone().unwrap();
|
||||
|
||||
match get_matches(&cli_config) {
|
||||
// `matches` here is a Struct with { args, subcommand }.
|
||||
// `args` is `HashMap<String, ArgData>` where `ArgData` is a struct with { value, occurances }.
|
||||
// `subcommand` is `Option<Box<SubcommandMatches>>` where `SubcommandMatches` is a struct with { name, matches }.
|
||||
Ok(matches) => {
|
||||
println!("{:?}", matches)
|
||||
}
|
||||
}
|
||||
Err(_) => {}
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
.run(context)
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user