Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Making Your Own CLI is incorrect #4145

Closed
DoodlesEpic opened this issue May 16, 2022 · 3 comments
Closed

[docs] Making Your Own CLI is incorrect #4145

DoodlesEpic opened this issue May 16, 2022 · 3 comments
Labels
type: documentation Need to update the API documentation

Comments

@DoodlesEpic
Copy link

DoodlesEpic commented May 16, 2022

https://tauri.studio/v1/guides/features/cli/#rust
On the documentation the page Making Your Own CLI has a section for reading matches with Rust, with the following code example:

use tauri::api::cli::get_matches;

fn main() {
  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");
}

This code however is incorrect since the signature of the function get_matches has been changed and now requires two arguments:

pub fn get_matches(cli: &CliConfig, package_info: &PackageInfo) -> crate::api::Result<Matches>

Trying to compile this will result in the following error:

error[E0061]: this function takes 2 arguments but 1 argument was supplied
  --> src/main.rs:12:11
   |
12 |     match get_matches(&cli_config) {
   |           ^^^^^^^^^^^ ----------- supplied 1 argument
   |           |
   |           expected 2 arguments
   |
note: function defined here
  --> /home/doodles/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-1.0.0-rc.10/src/api/cli.rs:97:8
   |
97 | pub fn get_matches(cli: &CliConfig, package_info: &PackageInfo) -> crate::api::Result<Matches> {
   |        ^^^^^^^^^^^
@DoodlesEpic DoodlesEpic added the type: documentation Need to update the API documentation label May 16, 2022
@lucasfernog
Copy link
Member

Thanks for the report. We'll address this tomorrow.

@sbeckeriv
Copy link

Hello,

While the docs are being updated if you find this issue you can run this code for the match with the rest of the example.

match get_matches(&cli_config, context.package_info())

Thanks!
Becker

@lucasfernog
Copy link
Member

Fixed by tauri-apps/tauri-docs@02d1dcc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Need to update the API documentation
Projects
None yet
Development

No branches or pull requests

3 participants