From 7e17d5a36b2cc2cc77e7b15796b14d639ed3cbf7 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Thu, 8 Dec 2016 15:36:18 -0500 Subject: [PATCH] fix(ZSH Completions): escapes square brackets in ZSH completions Since ZSH completions use `[ and ]` for descriptions, but clap args use `[ and ]` for possible values and other auxillary arg information, this was creating a conflict. clap now escapes any square brackets before writing the help, i.e. `\\[ and \\]` which removes conflicts. Alternatives would be to switch `[ and ]` for `( and )` but this would create a slight difference in help messages and completions. Closes #771 --- src/completions/zsh.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/completions/zsh.rs b/src/completions/zsh.rs index 6121a156c22..1aa15e55b00 100644 --- a/src/completions/zsh.rs +++ b/src/completions/zsh.rs @@ -129,7 +129,7 @@ fn subcommands_and_args_of(p: &Parser) -> String { fn add_sc(sc: &App, n: &str, ret: &mut Vec) { let s = format!("\"{name}:{help}\" \\", name = n, - help = sc.p.meta.about.unwrap_or("")); + help = sc.p.meta.about.unwrap_or("").replace("[", "\\[").replace("]", "\\]")); if !s.is_empty() { ret.push(s); } @@ -151,7 +151,7 @@ fn subcommands_and_args_of(p: &Parser) -> String { debugln!("iter;arg={}", arg.b.name); let a = format!("\"{name}:{help}\" \\", name = arg.b.name.to_ascii_uppercase(), - help = arg.b.help.unwrap_or("")); + help = arg.b.help.unwrap_or("").replace("[", "\\[").replace("]", "\\]")); if !a.is_empty() { ret.push(a); @@ -299,7 +299,7 @@ fn write_opts_of(p: &Parser) -> String { let mut ret = vec![]; for o in p.opts() { debugln!("iter;o={}", o.name()); - let help = o.help().unwrap_or(""); + let help = o.help().unwrap_or("").replace("[", "\\[").replace("]", "\\]"); let mut conflicts = get_zsh_arg_conflicts!(p, o, INTERNAL_ERROR_MSG); conflicts = if conflicts.is_empty() { String::new() @@ -349,7 +349,7 @@ fn write_flags_of(p: &Parser) -> String { let mut ret = vec![]; for f in p.flags() { debugln!("iter;f={}", f.name()); - let help = f.help().unwrap_or(""); + let help = f.help().unwrap_or("").replace("[", "\\[").replace("]", "\\]"); let mut conflicts = get_zsh_arg_conflicts!(p, f, INTERNAL_ERROR_MSG); conflicts = if conflicts.is_empty() { String::new()