fix(complete)!: Remove --register

Our focus is on encouraging people to generate this on shell load so its
more "auto-updating" as programs are updated.
Having a flag for saving to a file is counter to that goal.
This commit is contained in:
Ed Page 2024-08-10 19:33:49 -05:00
parent ce56785427
commit c9df58bcf7
6 changed files with 4 additions and 35 deletions

View file

@ -174,16 +174,7 @@ impl CompleteCommand {
#[derive(clap::Args, Clone, Debug)]
#[command(about = None, long_about = None)]
pub struct CompleteArgs {
/// Path to write completion-registration to
#[arg(long, value_name = "PATH")]
register: Option<std::path::PathBuf>,
#[arg(
raw = true,
value_name = "ARG",
hide = true,
conflicts_with = "register"
)]
#[arg(raw = true, value_name = "ARG", hide = true)]
comp_words: Option<Vec<OsString>>,
/// Specify shell to complete for
@ -219,23 +210,12 @@ impl CompleteArgs {
shell.write_complete(cmd, comp_words.clone(), current_dir.as_deref(), &mut buf)?;
std::io::stdout().write_all(&buf)?;
} else {
let out_path = self
.register
.as_deref()
.unwrap_or(std::path::Path::new("-"));
let name = cmd.get_name();
let bin = cmd.get_bin_name().unwrap_or_else(|| cmd.get_name());
let mut buf = Vec::new();
shell.write_registration(name, bin, bin, &mut buf)?;
if out_path == std::path::Path::new("-") {
std::io::stdout().write_all(&buf)?;
} else if out_path.is_dir() {
let out_path = out_path.join(shell.file_name(name));
std::fs::write(out_path, buf)?;
} else {
std::fs::write(out_path, buf)?;
}
std::io::stdout().write_all(&buf)?;
}
Ok(())

View file

@ -238,16 +238,12 @@ _exhaustive() {
return 0
;;
exhaustive__complete)
opts="-h -V --register --shell --global --help --version [ARG]..."
opts="-h -V --shell --global --help --version [ARG]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--register)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--shell)
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
return 0

View file

@ -239,7 +239,6 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand --version 'Print version'
}
&'exhaustive;complete'= {
cand --register 'Path to write completion-registration to'
cand --shell 'Specify shell to complete for'
cand --global 'everywhere'
cand -h 'Print help'

View file

@ -136,7 +136,6 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l email -r
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -l global -d 'everywhere'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand hint" -s V -l version -d 'Print version'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand complete" -l register -d 'Path to write completion-registration to' -r -F
complete -c exhaustive -n "__fish_exhaustive_using_subcommand complete" -l shell -d 'Specify shell to complete for' -r -f -a "{bash\t'',elvish\t'',fish\t'',powershell\t'',zsh\t''}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand complete" -l global -d 'everywhere'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand complete" -s h -l help -d 'Print help'

View file

@ -325,7 +325,6 @@ _arguments "${_arguments_options[@]}" : \
;;
(complete)
_arguments "${_arguments_options[@]}" : \
'--register=[Path to write completion-registration to]:PATH:_files' \
'--shell=[Specify shell to complete for]:NAME:(bash elvish fish powershell zsh)' \
'--global[everywhere]' \
'-h[Print help]' \

View file

@ -330,11 +330,7 @@ pub(crate) fn register_example<R: completest::RuntimeBuilder>(context: &str, nam
let mut registration = std::process::Command::new(&bin_path);
match context {
"static" => registration.args([format!("--generate={shell_name}")]),
"dynamic" => registration.args([
"complete".to_owned(),
"--register=-".to_owned(),
format!("--shell={shell_name}"),
]),
"dynamic" => registration.args(["complete".to_owned(), format!("--shell={shell_name}")]),
_ => unreachable!("unsupported context {}", context),
};
let registration = registration.output().unwrap();