Merge pull request #536 from rustic-rs/fix-shell-completions

Fix shell completions
This commit is contained in:
aawsome 2023-03-25 21:34:47 +01:00 committed by GitHub
commit a834e12fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 13 deletions

View File

@ -4,6 +4,7 @@ Breaking changes:
Bugs fixed:
- Fixed compiliation on OpenBSD.
- Fixed shell completions.
New features:
- REST backend: Set User-Agent header

View File

@ -46,7 +46,7 @@ pub struct LocalSourceOptions {
ignore_devid: bool,
/// Glob pattern to exclude/include (can be specified multiple times)
#[clap(long, short = 'g', help_heading = "EXCLUDE OPTIONS")]
#[clap(long, help_heading = "EXCLUDE OPTIONS")]
#[merge(strategy = merge::vec::overwrite_empty)]
glob: Vec<String>,

View File

@ -1,3 +1,5 @@
use std::io::Write;
use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::{generate, shells, Generator};
@ -16,18 +18,25 @@ pub(super) enum Variant {
pub(super) fn execute(opts: Opts) {
match opts.sh {
Variant::Bash => generate_completion(shells::Bash),
Variant::Fish => generate_completion(shells::Fish),
Variant::Zsh => generate_completion(shells::Zsh),
Variant::Bash => generate_completion(shells::Bash, &mut std::io::stdout()),
Variant::Fish => generate_completion(shells::Fish, &mut std::io::stdout()),
Variant::Zsh => generate_completion(shells::Zsh, &mut std::io::stdout()),
}
}
fn generate_completion<G: Generator>(shell: G) {
fn generate_completion<G: Generator>(shell: G, buf: &mut dyn Write) {
let mut command = super::Opts::command();
generate(
shell,
&mut command,
env!("CARGO_BIN_NAME"),
&mut std::io::stdout(),
);
generate(shell, &mut command, env!("CARGO_BIN_NAME"), buf);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_completions() {
generate_completion(shells::Bash, &mut std::io::sink());
generate_completion(shells::Fish, &mut std::io::sink());
generate_completion(shells::Zsh, &mut std::io::sink());
}
}

View File

@ -56,7 +56,7 @@ struct SnapOpts {
dry_run: bool,
/// Also remove defect snapshots - WARNING: This can result in data loss!
#[clap(long, short = 'n')]
#[clap(long)]
delete: bool,
/// Append this suffix to repaired directory or file name

View File

@ -43,7 +43,7 @@ pub(super) struct Opts {
numeric_id: bool,
/// Don't restore ownership (user/group)
#[clap(long, conflicts_with = "numeric_id")]
#[clap(long, conflicts_with = "numeric-id")]
no_ownership: bool,
/// Warm up needed data pack files by only requesting them without processing