Skip to content

Commit 0290978

Browse files
authored
Fix shell completions (#522)
We had a panic happen on running `py-spy completions bash`, due to clap-rs/clap#3826 . Fixes #520
1 parent 35231f7 commit 0290978

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ edition="2021"
1313

1414
[dependencies]
1515
anyhow = "1"
16-
clap = {version="3.1", features=["wrap_help", "cargo", "derive"]}
17-
clap_complete="3.1"
16+
clap = {version="3.2", features=["wrap_help", "cargo", "derive"]}
17+
clap_complete="3.2"
1818
console = "0.15"
1919
ctrlc = "3"
2020
indicatif = "0.16"

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ impl Config {
323323
config.dump_locals = matches.occurrences_of("locals");
324324
},
325325
"completions" => {
326-
let shell = matches.value_of_t::<clap_complete::Shell>("shell")?;
326+
let shell = matches.get_one::<clap_complete::Shell>("shell").unwrap();
327327
let app_name = app.get_name().to_string();
328-
clap_complete::generate(shell, &mut app, app_name, &mut std::io::stdout());
328+
clap_complete::generate(*shell, &mut app, app_name, &mut std::io::stdout());
329329
std::process::exit(0);
330330
}
331331
_ => {}

tests/integration_test.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,18 @@ def test_thread_names(self):
9999
if expected_thread_names == actual_thread_names:
100100
break
101101
if expected_thread_names != actual_thread_names:
102-
print("failed to get thread names", expected_thread_names, actual_thread_names)
102+
print(
103+
"failed to get thread names",
104+
expected_thread_names,
105+
actual_thread_names,
106+
)
103107

104108
assert expected_thread_names == actual_thread_names
105109

110+
def test_shell_completions(self):
111+
cmdline = [PYSPY, "completions", "bash"]
112+
subprocess.check_output(cmdline)
113+
106114

107115
def _get_script(name):
108116
base_dir = os.path.dirname(__file__)

0 commit comments

Comments
 (0)