refactor(get)!: case sensitive by default

- remove `--sensitive(-s)`
- add `--ignore-case(-I)`
This commit is contained in:
Bahex 2025-05-04 10:57:12 +03:00
parent e0812f6bc8
commit 05ff3c8e8e

View File

@ -46,9 +46,9 @@ If multiple cell paths are given, this will produce a list of values."#
Some('i'), Some('i'),
) )
.switch( .switch(
"sensitive", "ignore-case",
"get path in a case sensitive manner", "get path in a case insensitive manner (make all cell path members case insensitive)",
Some('s'), Some('I'),
) )
.allow_variants_without_examples(true) .allow_variants_without_examples(true)
.category(Category::Filters) .category(Category::Filters)
@ -87,12 +87,12 @@ If multiple cell paths are given, this will produce a list of values."#
}, },
Example { Example {
description: "Getting Path/PATH in a case insensitive way", description: "Getting Path/PATH in a case insensitive way",
example: "$env | get paTH", example: "$env | get --ignore-case paTH",
result: None, result: None,
}, },
Example { Example {
description: "Getting Path in a case sensitive way, won't work for 'PATH'", description: "Getting Path in a case sensitive way, won't work for 'PATH'",
example: "$env | get --sensitive Path", example: "$env | get Path",
result: None, result: None,
}, },
] ]
@ -111,14 +111,14 @@ If multiple cell paths are given, this will produce a list of values."#
let cell_path: CellPath = call.req_const(working_set, 0)?; let cell_path: CellPath = call.req_const(working_set, 0)?;
let rest: Vec<CellPath> = call.rest_const(working_set, 1)?; let rest: Vec<CellPath> = call.rest_const(working_set, 1)?;
let ignore_errors = call.has_flag_const(working_set, "ignore-errors")?; let ignore_errors = call.has_flag_const(working_set, "ignore-errors")?;
let sensitive = call.has_flag_const(working_set, "sensitive")?; let ignore_case = call.has_flag_const(working_set, "ignore-case")?;
let metadata = input.metadata(); let metadata = input.metadata();
action( action(
input, input,
cell_path, cell_path,
rest, rest,
ignore_errors, ignore_errors,
sensitive, ignore_case,
working_set.permanent().signals().clone(), working_set.permanent().signals().clone(),
call.head, call.head,
) )
@ -135,14 +135,14 @@ If multiple cell paths are given, this will produce a list of values."#
let cell_path: CellPath = call.req(engine_state, stack, 0)?; let cell_path: CellPath = call.req(engine_state, stack, 0)?;
let rest: Vec<CellPath> = call.rest(engine_state, stack, 1)?; let rest: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let ignore_errors = call.has_flag(engine_state, stack, "ignore-errors")?; let ignore_errors = call.has_flag(engine_state, stack, "ignore-errors")?;
let sensitive = call.has_flag(engine_state, stack, "sensitive")?; let ignore_case = call.has_flag(engine_state, stack, "ignore-case")?;
let metadata = input.metadata(); let metadata = input.metadata();
action( action(
input, input,
cell_path, cell_path,
rest, rest,
ignore_errors, ignore_errors,
sensitive, ignore_case,
engine_state.signals().clone(), engine_state.signals().clone(),
call.head, call.head,
) )
@ -155,7 +155,7 @@ fn action(
mut cell_path: CellPath, mut cell_path: CellPath,
mut rest: Vec<CellPath>, mut rest: Vec<CellPath>,
ignore_errors: bool, ignore_errors: bool,
sensitive: bool, ignore_case: bool,
signals: Signals, signals: Signals,
span: Span, span: Span,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
@ -166,6 +166,13 @@ fn action(
} }
} }
if ignore_case {
cell_path.make_insensitive();
for path in &mut rest {
path.make_insensitive();
}
}
match input { match input {
PipelineData::Empty => return Err(ShellError::PipelineEmpty { dst_span: span }), PipelineData::Empty => return Err(ShellError::PipelineEmpty { dst_span: span }),
// Allow chaining of get -i // Allow chaining of get -i