Skip to content

Commit 57cce4b

Browse files
YatekiiNoah Hüsser
andauthored
Add a --manual flag to the autocomplete install command (probe-rs#3579)
Co-authored-by: Noah Hüsser <noahs@huesser.dev>
1 parent 65628ac commit 57cce4b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Add a --manual flag to the autocomplete install command
2+
3+
This flag prints the autocomplete script to stdout instead of installing it.
4+
5+
This feature is useful for distro maintainers or other special packaging requirements
6+
which install autocomplete scripts with their own mechanism.

probe-rs-tools/src/bin/probe-rs/cmd/complete.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl Cmd {
3232
.ok_or_else(|| anyhow!("The current shell could not be determined. Please specify a shell with the --shell argument."))?;
3333

3434
match &self.kind {
35-
CompleteKind::Install => {
36-
self.install(shell)?;
35+
CompleteKind::Install { manual } => {
36+
self.install(shell, *manual)?;
3737
}
3838
CompleteKind::ProbeList { input } => {
3939
self.probe_list(lister, input)?;
@@ -50,7 +50,7 @@ impl Cmd {
5050
///
5151
/// If the shell cannot be determined or the auto-install is not implemented yet,
5252
/// the function prints the script with instructions for the user.
53-
pub fn install(&self, shell: Shell) -> Result<()> {
53+
pub fn install(&self, shell: Shell, manual: bool) -> Result<()> {
5454
let mut command = <Cli as CommandFactory>::command();
5555
let path: PathBuf = std::env::args_os().next().unwrap().into();
5656
let name = path.file_name().unwrap().to_str().unwrap();
@@ -62,6 +62,11 @@ impl Cmd {
6262

6363
let file_name = shell.file_name(BIN_NAME);
6464

65+
if manual {
66+
println!("{script}");
67+
return Ok(());
68+
}
69+
6570
match shell {
6671
Shell::Zsh => {
6772
Zsh.install(&file_name, &script)?;
@@ -99,7 +104,14 @@ impl Cmd {
99104
#[clap(verbatim_doc_comment)]
100105
pub enum CompleteKind {
101106
/// Installs the autocomplete script for the correct shell.
102-
Install,
107+
Install {
108+
/// Just print the script to stdout if this flag is active.
109+
///
110+
/// This is useful for packaging probe-rs for installers that have their
111+
/// own autocomplete packaging mechanisms.
112+
#[clap(short, long)]
113+
manual: bool,
114+
},
103115
/// Lists the probes that are currently plugged in in a way that the shell understands.
104116
ProbeList {
105117
/// The already entered user input that will be used to filter the list.

0 commit comments

Comments
 (0)