fn print_completions(mut app: clap::App, rest_args: Vec<String>) -> Error {
    let bin_name = match app.get_bin_name() {
        // This name is borrowed from `app`, and `gen_completions_to()` mutably
        // borrows `app`, so we need to do a clone
        Some(name) => name.to_owned(),
        None => return Error::with_description("Missing binary name", ErrorKind::EmptyValue),
    };
    if rest_args.len() != 1 {
        return Error::with_description(
            "Usage: xh print_completions <SHELL>",
            ErrorKind::WrongNumberOfValues,
        );
    }
    let shell = match rest_args[0].parse() {
        Ok(shell) => shell,
        Err(_) => return Error::with_description("Unknown shell name", ErrorKind::InvalidValue),
    };
    let mut buf = Vec::new();
    app.gen_completions_to(bin_name, shell, &mut buf);
    let mut completions = String::from_utf8(buf).unwrap();
    if matches!(shell, clap::Shell::Fish) {
        // We don't have (proper) subcommands, so this check is unnecessary and
        // slightly harmful
        // See https://github.com/clap-rs/clap/pull/2359, currently unreleased
        completions = completions.replace(r#" -n "__fish_use_subcommand""#, "");
    }
    print!("{}", completions);
    safe_exit();
}
// This signature is a little weird: we either return an error or don't
// return at all
This signature is a little weird: we either return an error or don't
return at all
This signature is a little weird : we either return an error or don ' t return at all
fn print_completions(mut app: clap::App, rest_args: Vec<String>) -> Error {
    let bin_name = match app.get_bin_name() {
        // This name is borrowed from `app`, and `gen_completions_to()` mutably
        // borrows `app`, so we need to do a clone
        Some(name) => name.to_owned(),
        None => return Error::with_description("Missing binary name", ErrorKind::EmptyValue),
    };
    if rest_args.len() != 1 {
        return Error::with_description(
            "Usage: xh print_completions <SHELL>",
            ErrorKind::WrongNumberOfValues,
        );
    }
    let shell = match rest_args[0].parse() {
        Ok(shell) => shell,
        Err(_) => return Error::with_description("Unknown shell name", ErrorKind::InvalidValue),
    };
    let mut buf = Vec::new();
    app.gen_completions_to(bin_name, shell, &mut buf);
    let mut completions = String::from_utf8(buf).unwrap();
    if matches!(shell, clap::Shell::Fish) {
        // We don't have (proper) subcommands, so this check is unnecessary and
        // slightly harmful
        // See https://github.com/clap-rs/clap/pull/2359, currently unreleased
        completions = completions.replace(r#" -n "__fish_use_subcommand""#, "");
    }
    print!("{}", completions);
    safe_exit();
}
fn print_completions ( mut app : clap :: App , rest_args : Vec < String > ) -> Error { let bin_name = match app . get_bin_name ( ) { // This name is borrowed from `app`, and `gen_completions_to()` mutably // borrows `app`, so we need to do a clone Some ( name ) => name . to_owned ( ) , None => return Error :: with_description ( " " , ErrorKind :: EmptyValue ) , } ; if rest_args . len ( ) != 1 { return Error :: with_description ( " " , ErrorKind :: WrongNumberOfValues , ) ; } let shell = match rest_args [ 0 ] . parse ( ) { Ok ( shell ) => shell , Err ( _ ) => return Error :: with_description ( " " , ErrorKind :: InvalidValue ) , } ; let mut buf = Vec :: new ( ) ; app . gen_completions_to ( bin_name , shell , & mut buf ) ; let mut completions = String :: from_utf8 ( buf ) . unwrap ( ) ; if matches ! ( shell clap Shell Fish ) { // We don't have (proper) subcommands, so this check is unnecessary and // slightly harmful // See https://github.com/clap-rs/clap/pull/2359, currently unreleased completions = completions . replace ( r#" -n "__fish_use_subcommand""# , " " ) ; } print ! ( " " completions ) ; safe_exit ( ) ; }
This signature is a little weird: we either return an error or don't
return at all
This signature is a little weird : we either return an error or don ' t return at all
app
clap::App
rest_args
Vec<String>
app
clap::App
rest_args
Vec<String>