Skip to content

Commit

Permalink
Fix usage of has_flag in registry query
Browse files Browse the repository at this point in the history
  • Loading branch information
NotLebedev committed Jan 6, 2024
1 parent 45c756a commit 2de5a91
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/nu-command/src/system/registry_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn registry_query(
let registry_key_span = &registry_key.clone().span;
let registry_value: Option<Spanned<String>> = call.opt(engine_state, stack, 1)?;

let reg_hive = get_reg_hive(call)?;
let reg_hive = get_reg_hive(engine_state, stack, call)?;
let reg_key = reg_hive.open_subkey(registry_key.item)?;

if registry_value.is_none() {
Expand Down Expand Up @@ -144,14 +144,22 @@ fn registry_query(
}
}

fn get_reg_hive(call: &Call) -> Result<RegKey, ShellError> {
fn get_reg_hive(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
) -> Result<RegKey, ShellError> {
let flags: Vec<_> = [
"hkcr", "hkcu", "hklm", "hku", "hkpd", "hkpt", "hkpnls", "hkcc", "hkdd", "hkculs",
]
.iter()
.copied()
.filter(|flag| call.has_flag(flag))
.collect();
.filter_map(|flag| match call.has_flag(engine_state, stack, flag) {
Ok(true) => Some(Ok(flag)),
Ok(false) => None,
Err(e) => Some(Err(e)),
})
.collect()?;

Check failure on line 162 in crates/nu-command/src/system/registry_query.rs

View workflow job for this annotation

GitHub Actions / fmt-clippy (windows-latest, default)

type annotations needed

Check failure on line 162 in crates/nu-command/src/system/registry_query.rs

View workflow job for this annotation

GitHub Actions / std-lib-and-python-virtualenv (windows-latest, py)

type annotations needed

Check failure on line 162 in crates/nu-command/src/system/registry_query.rs

View workflow job for this annotation

GitHub Actions / tests (windows-latest, default)

type annotations needed
if flags.len() > 1 {
return Err(ShellError::GenericError {
error: "Only one registry key can be specified".into(),
Expand Down

0 comments on commit 2de5a91

Please sign in to comment.