mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:56:14 +02:00
Use variable names directly in the format strings (#7906)
# Description Lint: `clippy::uninlined_format_args` More readable in most situations. (May be slightly confusing for modifier format strings https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters) Alternative to #7865 # User-Facing Changes None intended # Tests + Formatting (Ran `cargo +stable clippy --fix --workspace -- -A clippy::all -D clippy::uninlined_format_args` to achieve this. Depends on Rust `1.67`)
This commit is contained in:
committed by
GitHub
parent
6ae497eedc
commit
ab480856a5
@ -106,8 +106,7 @@ where
|
||||
error: ShellError::GenericError(
|
||||
"Rotate left result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
"{} of the specified number of bytes rotate left {} bits exceed limit",
|
||||
val, bits
|
||||
"{val} of the specified number of bytes rotate left {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
|
@ -110,8 +110,7 @@ where
|
||||
error: ShellError::GenericError(
|
||||
"Rotate right result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
"{} of the specified number of bytes rotate right {} bits exceed limit",
|
||||
val, bits
|
||||
"{val} of the specified number of bytes rotate right {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
|
@ -118,8 +118,7 @@ where
|
||||
error: ShellError::GenericError(
|
||||
"Shift left result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
"{} of the specified number of bytes shift left {} bits exceed limit",
|
||||
val, bits
|
||||
"{val} of the specified number of bytes shift left {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
@ -131,10 +130,7 @@ where
|
||||
None => Value::Error {
|
||||
error: ShellError::GenericError(
|
||||
"Shift left failed".to_string(),
|
||||
format!(
|
||||
"{} shift left {} bits failed, you may shift too many bits",
|
||||
val, bits
|
||||
),
|
||||
format!("{val} shift left {bits} bits failed, you may shift too many bits"),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
|
@ -108,8 +108,7 @@ where
|
||||
error: ShellError::GenericError(
|
||||
"Shift right result beyond the range of 64 bit signed number".to_string(),
|
||||
format!(
|
||||
"{} of the specified number of bytes shift right {} bits exceed limit",
|
||||
val, bits
|
||||
"{val} of the specified number of bytes shift right {bits} bits exceed limit"
|
||||
),
|
||||
Some(span),
|
||||
None,
|
||||
@ -121,10 +120,7 @@ where
|
||||
None => Value::Error {
|
||||
error: ShellError::GenericError(
|
||||
"Shift right failed".to_string(),
|
||||
format!(
|
||||
"{} shift right {} bits failed, you may shift too many bits",
|
||||
val, bits
|
||||
),
|
||||
format!("{val} shift right {bits} bits failed, you may shift too many bits"),
|
||||
Some(span),
|
||||
None,
|
||||
Vec::new(),
|
||||
|
@ -166,7 +166,7 @@ fn run_histogram(
|
||||
ShellError::UnsupportedInput(
|
||||
"Since --column-name was not provided, only lists of hashable values are supported.".to_string(),
|
||||
format!(
|
||||
"input type: {:?}", t
|
||||
"input type: {t:?}"
|
||||
),
|
||||
head_span,
|
||||
span,
|
||||
|
@ -103,31 +103,31 @@ fn fmt_it(num: i64, span: Span) -> Value {
|
||||
let mut vals = vec![];
|
||||
|
||||
cols.push("binary".into());
|
||||
vals.push(Value::string(format!("{:#b}", num), span));
|
||||
vals.push(Value::string(format!("{num:#b}"), span));
|
||||
|
||||
cols.push("debug".into());
|
||||
vals.push(Value::string(format!("{:#?}", num), span));
|
||||
vals.push(Value::string(format!("{num:#?}"), span));
|
||||
|
||||
cols.push("display".into());
|
||||
vals.push(Value::string(format!("{}", num), span));
|
||||
vals.push(Value::string(format!("{num}"), span));
|
||||
|
||||
cols.push("lowerexp".into());
|
||||
vals.push(Value::string(format!("{:#e}", num), span));
|
||||
vals.push(Value::string(format!("{num:#e}"), span));
|
||||
|
||||
cols.push("lowerhex".into());
|
||||
vals.push(Value::string(format!("{:#x}", num), span));
|
||||
vals.push(Value::string(format!("{num:#x}"), span));
|
||||
|
||||
cols.push("octal".into());
|
||||
vals.push(Value::string(format!("{:#o}", num), span));
|
||||
vals.push(Value::string(format!("{num:#o}"), span));
|
||||
|
||||
// cols.push("pointer".into());
|
||||
// vals.push(Value::string(format!("{:#p}", &num), span));
|
||||
|
||||
cols.push("upperexp".into());
|
||||
vals.push(Value::string(format!("{:#E}", num), span));
|
||||
vals.push(Value::string(format!("{num:#E}"), span));
|
||||
|
||||
cols.push("upperhex".into());
|
||||
vals.push(Value::string(format!("{:#X}", num), span));
|
||||
vals.push(Value::string(format!("{num:#X}"), span));
|
||||
|
||||
Value::Record { cols, vals, span }
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
return Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
"timestamp is out of range; it should between -8e+12 and 8e+12".to_string(),
|
||||
format!("timestamp is {:?}", ts),
|
||||
format!("timestamp is {ts:?}"),
|
||||
head,
|
||||
// Again, can safely unwrap this from here on
|
||||
input.expect_span(),
|
||||
|
@ -367,8 +367,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
"string".to_string(),
|
||||
span,
|
||||
Some(format!(
|
||||
r#"string "{}" does not represent a valid integer"#,
|
||||
trimmed
|
||||
r#"string "{trimmed}" does not represent a valid integer"#
|
||||
)),
|
||||
)),
|
||||
},
|
||||
|
@ -206,7 +206,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
if decimals {
|
||||
let decimal_value = digits.unwrap_or(2) as usize;
|
||||
Value::String {
|
||||
val: format!("{:.*}", decimal_value, val),
|
||||
val: format!("{val:.decimal_value$}"),
|
||||
span,
|
||||
}
|
||||
} else {
|
||||
|
@ -41,7 +41,7 @@ impl Command for Ast {
|
||||
let mut working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
let (output, err) = parse(&mut working_set, None, pipeline.item.as_bytes(), false, &[]);
|
||||
eprintln!("output: {:#?}\nerror: {:#?}", output, err);
|
||||
eprintln!("output: {output:#?}\nerror: {err:#?}");
|
||||
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ pub fn highlight_search_string(
|
||||
needle: &str,
|
||||
string_style: &Style,
|
||||
) -> Result<String, ShellError> {
|
||||
let regex_string = format!("(?i){}", needle);
|
||||
let regex_string = format!("(?i){needle}");
|
||||
let regex = match Regex::new(®ex_string) {
|
||||
Ok(regex) => regex,
|
||||
Err(err) => {
|
||||
|
@ -117,7 +117,7 @@ fn action(
|
||||
|
||||
let table_columns_creation = columns
|
||||
.iter()
|
||||
.map(|(name, sql_type)| format!("{} {}", name, sql_type))
|
||||
.map(|(name, sql_type)| format!("{name} {sql_type}"))
|
||||
.join(",");
|
||||
|
||||
// get the values
|
||||
@ -156,10 +156,8 @@ fn action(
|
||||
let conn = open_sqlite_db(Path::new(&file.item), file.span)?;
|
||||
|
||||
// create a string for sql table creation
|
||||
let create_statement = format!(
|
||||
"CREATE TABLE IF NOT EXISTS {} ({})",
|
||||
table_name, table_columns_creation
|
||||
);
|
||||
let create_statement =
|
||||
format!("CREATE TABLE IF NOT EXISTS {table_name} ({table_columns_creation})");
|
||||
|
||||
// prepare the string as a sqlite statement
|
||||
let mut stmt = conn.prepare(&create_statement).map_err(|e| {
|
||||
@ -191,7 +189,7 @@ fn action(
|
||||
// ('dd', 'ee', 'ff')
|
||||
|
||||
// create the string for inserting data into the table
|
||||
let insert_statement = format!("INSERT INTO {} VALUES {}", table_name, table_values);
|
||||
let insert_statement = format!("INSERT INTO {table_name} VALUES {table_values}");
|
||||
|
||||
// prepare the string as a sqlite statement
|
||||
let mut stmt = conn.prepare(&insert_statement).map_err(|e| {
|
||||
@ -264,13 +262,13 @@ fn nu_value_to_string(value: Value, separator: &str) -> String {
|
||||
.join(separator),
|
||||
Value::LazyRecord { val, .. } => match val.collect() {
|
||||
Ok(val) => nu_value_to_string(val, separator),
|
||||
Err(error) => format!("{:?}", error),
|
||||
Err(error) => format!("{error:?}"),
|
||||
},
|
||||
Value::Block { val, .. } => format!("<Block {}>", val),
|
||||
Value::Closure { val, .. } => format!("<Closure {}>", val),
|
||||
Value::Block { val, .. } => format!("<Block {val}>"),
|
||||
Value::Closure { val, .. } => format!("<Closure {val}>"),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{:?}", error),
|
||||
Value::Binary { val, .. } => format!("{:?}", val),
|
||||
Value::Error { error } => format!("{error:?}"),
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ fn read_single_table(
|
||||
call_span: Span,
|
||||
ctrlc: Option<Arc<AtomicBool>>,
|
||||
) -> Result<Value, rusqlite::Error> {
|
||||
let stmt = conn.prepare(&format!("SELECT * FROM {}", table_name))?;
|
||||
let stmt = conn.prepare(&format!("SELECT * FROM {table_name}"))?;
|
||||
prepared_statement_to_nu_list(stmt, call_span, ctrlc)
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ fn read_entire_sqlite_db(
|
||||
let table_name: String = row?;
|
||||
table_names.push(table_name.clone());
|
||||
|
||||
let table_stmt = conn.prepare(&format!("select * from [{}]", table_name))?;
|
||||
let table_stmt = conn.prepare(&format!("select * from [{table_name}]"))?;
|
||||
let rows = prepared_statement_to_nu_list(table_stmt, call_span, ctrlc.clone())?;
|
||||
tables.push(rows);
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ where
|
||||
.unwrap_or(Locale::en_US);
|
||||
let format = date_time.format_localized(formatter, locale);
|
||||
|
||||
match formatter_buf.write_fmt(format_args!("{}", format)) {
|
||||
match formatter_buf.write_fmt(format_args!("{format}")) {
|
||||
Ok(_) => Value::String {
|
||||
val: formatter_buf,
|
||||
span,
|
||||
|
@ -495,7 +495,7 @@ pub fn create_default_context() -> EngineState {
|
||||
};
|
||||
|
||||
if let Err(err) = engine_state.merge_delta(delta) {
|
||||
eprintln!("Error creating default context: {:?}", err);
|
||||
eprintln!("Error creating default context: {err:?}");
|
||||
}
|
||||
|
||||
engine_state
|
||||
|
@ -79,7 +79,7 @@ impl Command for ConfigReset {
|
||||
}
|
||||
}
|
||||
if let Ok(mut file) = std::fs::File::create(nu_config) {
|
||||
if writeln!(&mut file, "{}", config_file).is_err() {
|
||||
if writeln!(&mut file, "{config_file}").is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"config.nu could not be written to".into(),
|
||||
span,
|
||||
@ -102,7 +102,7 @@ impl Command for ConfigReset {
|
||||
}
|
||||
}
|
||||
if let Ok(mut file) = std::fs::File::create(env_config) {
|
||||
if writeln!(&mut file, "{}", config_file).is_err() {
|
||||
if writeln!(&mut file, "{config_file}").is_err() {
|
||||
return Err(ShellError::FileNotFoundCustom(
|
||||
"env.nu could not be written to".into(),
|
||||
span,
|
||||
|
2
crates/nu-command/src/env/env_command.rs
vendored
2
crates/nu-command/src/env/env_command.rs
vendored
@ -54,7 +54,7 @@ impl Command for Env {
|
||||
vals.push(Value::string(name, span));
|
||||
|
||||
cols.push("type".into());
|
||||
vals.push(Value::string(format!("{}", val_type), span));
|
||||
vals.push(Value::string(format!("{val_type}"), span));
|
||||
|
||||
cols.push("value".into());
|
||||
vals.push(val);
|
||||
|
@ -251,7 +251,7 @@ mod test_examples {
|
||||
{:?}",
|
||||
declared_type_transformations
|
||||
.difference(&witnessed_type_transformations)
|
||||
.map(|(s1, s2)| format!("{} -> {}", s1, s2))
|
||||
.map(|(s1, s2)| format!("{s1} -> {s2}"))
|
||||
.join(", ")
|
||||
);
|
||||
}
|
||||
@ -273,7 +273,7 @@ mod test_examples {
|
||||
nu_parser::parse(&mut working_set, None, contents.as_bytes(), false, &[]);
|
||||
|
||||
if let Some(err) = err {
|
||||
panic!("test parse error in `{}`: {:?}", contents, err)
|
||||
panic!("test parse error in `{contents}`: {err:?}")
|
||||
}
|
||||
|
||||
(output, working_set.render())
|
||||
|
@ -93,14 +93,14 @@ impl Command for Cd {
|
||||
Err(e) => {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
v.span,
|
||||
Some(format!("IO Error: {:?}", e)),
|
||||
Some(format!("IO Error: {e:?}")),
|
||||
))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
v.span,
|
||||
Some(format!("IO Error: {:?}", e1)),
|
||||
Some(format!("IO Error: {e1:?}")),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -123,7 +123,7 @@ impl Command for Cd {
|
||||
Err(e) => {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
v.span,
|
||||
Some(format!("IO Error: {:?}", e)),
|
||||
Some(format!("IO Error: {e:?}")),
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -142,14 +142,14 @@ impl Command for Cd {
|
||||
Err(e) => {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
v.span,
|
||||
Some(format!("IO Error: {:?}", e)),
|
||||
Some(format!("IO Error: {e:?}")),
|
||||
))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
v.span,
|
||||
Some(format!("IO Error: {:?}", e1)),
|
||||
Some(format!("IO Error: {e1:?}")),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -197,8 +197,7 @@ impl Command for Cd {
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
PermissionResult::PermissionDenied(reason) => Err(ShellError::IOError(format!(
|
||||
"Cannot change directory to {}: {}",
|
||||
path, reason
|
||||
"Cannot change directory to {path}: {reason}"
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
@ -168,8 +168,7 @@ impl Command for Cp {
|
||||
canonicalize_with(dst.as_path(), ¤t_dir_path).unwrap_or(dst);
|
||||
let res = if src == dst {
|
||||
let message = format!(
|
||||
"src {:?} and dst {:?} are identical(not copied)",
|
||||
source, destination
|
||||
"src {source:?} and dst {destination:?} are identical(not copied)"
|
||||
);
|
||||
|
||||
return Err(ShellError::GenericError(
|
||||
|
@ -145,7 +145,7 @@ impl Command for Glob {
|
||||
Err(e) => {
|
||||
return Err(ShellError::GenericError(
|
||||
"error with glob pattern".to_string(),
|
||||
format!("{}", e),
|
||||
format!("{e}"),
|
||||
Some(glob_pattern.span),
|
||||
None,
|
||||
Vec::new(),
|
||||
|
@ -70,7 +70,7 @@ impl Command for Mkdir {
|
||||
|
||||
if let Err(reason) = dir_res {
|
||||
return Err(ShellError::CreateNotPossible(
|
||||
format!("failed to create directory: {}", reason),
|
||||
format!("failed to create directory: {reason}"),
|
||||
call.positional_nth(i)
|
||||
.expect("already checked through directories")
|
||||
.span,
|
||||
|
@ -290,7 +290,7 @@ fn move_file(
|
||||
);
|
||||
if let Err(e) = interaction {
|
||||
return Err(ShellError::GenericError(
|
||||
format!("Error during interaction: {:}", e),
|
||||
format!("Error during interaction: {e:}"),
|
||||
"could not move".into(),
|
||||
None,
|
||||
None,
|
||||
@ -325,10 +325,10 @@ fn move_item(from: &Path, from_span: Span, to: &Path) -> Result<(), ShellError>
|
||||
Err(e) => {
|
||||
let error_kind = match e.kind {
|
||||
fs_extra::error::ErrorKind::Io(io) => {
|
||||
format!("I/O error: {}", io)
|
||||
format!("I/O error: {io}")
|
||||
}
|
||||
fs_extra::error::ErrorKind::StripPrefix(sp) => {
|
||||
format!("Strip prefix error: {}", sp)
|
||||
format!("Strip prefix error: {sp}")
|
||||
}
|
||||
fs_extra::error::ErrorKind::OsString(os) => {
|
||||
format!("OsString error: {:?}", os.to_str())
|
||||
@ -336,10 +336,7 @@ fn move_item(from: &Path, from_span: Span, to: &Path) -> Result<(), ShellError>
|
||||
_ => e.to_string(),
|
||||
};
|
||||
Err(ShellError::GenericError(
|
||||
format!(
|
||||
"Could not move {:?} to {:?}. Error Kind: {}",
|
||||
from, to, error_kind
|
||||
),
|
||||
format!("Could not move {from:?} to {to:?}. Error Kind: {error_kind}"),
|
||||
"could not move".into(),
|
||||
Some(from_span),
|
||||
None,
|
||||
|
@ -156,7 +156,7 @@ impl Command for Open {
|
||||
};
|
||||
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("from {}", ext).as_bytes(), &[]) {
|
||||
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
|
||||
Some(converter_id) => {
|
||||
let decl = engine_state.get_decl(converter_id);
|
||||
if let Some(block_id) = decl.get_block_id() {
|
||||
@ -167,7 +167,7 @@ impl Command for Open {
|
||||
}
|
||||
.map_err(|inner| {
|
||||
ShellError::GenericError(
|
||||
format!("Error while parsing as {}", ext),
|
||||
format!("Error while parsing as {ext}"),
|
||||
format!("Could not parse '{}' with `from {}`", path.display(), ext),
|
||||
Some(arg_span),
|
||||
Some(format!("Check out `help from {}` or `help from` for more options or open raw data with `open --raw '{}'`", ext, path.display())),
|
||||
|
@ -318,7 +318,7 @@ fn rm(
|
||||
);
|
||||
if let Err(e) = interaction {
|
||||
return Err(ShellError::GenericError(
|
||||
format!("Error during interaction: {:}", e),
|
||||
format!("Error during interaction: {e:}"),
|
||||
"could not move".into(),
|
||||
None,
|
||||
None,
|
||||
@ -375,7 +375,7 @@ fn rm(
|
||||
Ok(())
|
||||
} else if trash || (rm_always_trash && !permanent) {
|
||||
trash::delete(&f).map_err(|e: trash::Error| {
|
||||
Error::new(ErrorKind::Other, format!("{:?}\nTry '--trash' flag", e))
|
||||
Error::new(ErrorKind::Other, format!("{e:?}\nTry '--trash' flag"))
|
||||
})
|
||||
} else if metadata.is_file() || is_socket || is_fifo {
|
||||
std::fs::remove_file(&f)
|
||||
@ -403,7 +403,7 @@ fn rm(
|
||||
}
|
||||
|
||||
if let Err(e) = result {
|
||||
let msg = format!("Could not delete because: {:}", e);
|
||||
let msg = format!("Could not delete because: {e:}");
|
||||
Value::Error {
|
||||
error: ShellError::GenericError(
|
||||
msg,
|
||||
|
@ -215,7 +215,7 @@ fn convert_to_extension(
|
||||
input: PipelineData,
|
||||
span: Span,
|
||||
) -> Result<Vec<u8>, ShellError> {
|
||||
let converter = engine_state.find_decl(format!("to {}", extension).as_bytes(), &[]);
|
||||
let converter = engine_state.find_decl(format!("to {extension}").as_bytes(), &[]);
|
||||
|
||||
let output = match converter {
|
||||
Some(converter_id) => {
|
||||
|
@ -137,7 +137,7 @@ impl Command for Touch {
|
||||
|
||||
if let Err(err) = OpenOptions::new().write(true).create(true).open(&item) {
|
||||
return Err(ShellError::CreateNotPossible(
|
||||
format!("Failed to create file: {}", err),
|
||||
format!("Failed to create file: {err}"),
|
||||
call.positional_nth(index)
|
||||
.expect("already checked positional")
|
||||
.span,
|
||||
@ -151,7 +151,7 @@ impl Command for Touch {
|
||||
FileTime::from_system_time(date.expect("should be a valid date").into()),
|
||||
) {
|
||||
return Err(ShellError::ChangeModifiedTimeNotPossible(
|
||||
format!("Failed to change the modified time: {}", err),
|
||||
format!("Failed to change the modified time: {err}"),
|
||||
call.positional_nth(index)
|
||||
.expect("already checked positional")
|
||||
.span,
|
||||
@ -170,7 +170,7 @@ impl Command for Touch {
|
||||
),
|
||||
) {
|
||||
return Err(ShellError::ChangeAccessTimeNotPossible(
|
||||
format!("Failed to change the access time: {}", err),
|
||||
format!("Failed to change the access time: {err}"),
|
||||
call.positional_nth(index)
|
||||
.expect("already checked positional")
|
||||
.span,
|
||||
@ -183,7 +183,7 @@ impl Command for Touch {
|
||||
FileTime::from_system_time(date.expect("should be a valid date").into()),
|
||||
) {
|
||||
return Err(ShellError::ChangeAccessTimeNotPossible(
|
||||
format!("Failed to change the access time: {}", err),
|
||||
format!("Failed to change the access time: {err}"),
|
||||
call.positional_nth(index)
|
||||
.expect("already checked positional")
|
||||
.span,
|
||||
|
@ -79,7 +79,7 @@ impl Command for Watch {
|
||||
Err(e) => {
|
||||
return Err(ShellError::DirectoryNotFound(
|
||||
path_arg.span,
|
||||
Some(format!("IO Error: {:?}", e)),
|
||||
Some(format!("IO Error: {e:?}")),
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -227,7 +227,7 @@ impl Command for Watch {
|
||||
match rx.recv_timeout(CHECK_CTRL_C_FREQUENCY) {
|
||||
Ok(event) => {
|
||||
if verbose {
|
||||
eprintln!("{:?}", event);
|
||||
eprintln!("{event:?}");
|
||||
}
|
||||
let handler_result = match event {
|
||||
DebouncedEvent::Create(path) => event_handler("Create", path, None),
|
||||
|
@ -186,7 +186,7 @@ fn find_with_regex(
|
||||
let regex = flags.to_string() + regex.as_str();
|
||||
|
||||
let re = Regex::new(regex.as_str())
|
||||
.map_err(|e| ShellError::TypeMismatch(format!("invalid regex: {}", e), span))?;
|
||||
.map_err(|e| ShellError::TypeMismatch(format!("invalid regex: {e}"), span))?;
|
||||
|
||||
input.filter(
|
||||
move |value| match value {
|
||||
|
@ -213,7 +213,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
cols.iter().enumerate().for_each(|(idx, inner_record_col)| {
|
||||
if out.contains_key(inner_record_col) {
|
||||
out.insert(
|
||||
format!("{}_{}", column, inner_record_col),
|
||||
format!("{column}_{inner_record_col}"),
|
||||
vals[idx].clone(),
|
||||
);
|
||||
} else {
|
||||
@ -221,7 +221,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
}
|
||||
})
|
||||
} else if out.contains_key(column) {
|
||||
out.insert(format!("{}_{}", column, column), value.clone());
|
||||
out.insert(format!("{column}_{column}"), value.clone());
|
||||
} else {
|
||||
out.insert(column.to_string(), value.clone());
|
||||
}
|
||||
@ -261,7 +261,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
parent_column_index: column_index,
|
||||
});
|
||||
} else if out.contains_key(column) {
|
||||
out.insert(format!("{}_{}", column, column), value.clone());
|
||||
out.insert(format!("{column}_{column}"), value.clone());
|
||||
} else {
|
||||
out.insert(column.to_string(), value.clone());
|
||||
}
|
||||
@ -358,7 +358,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
if index == parent_column_index {
|
||||
for (col, val) in inner_cols.iter().zip(inner_vals.iter()) {
|
||||
if record_cols.contains(col) {
|
||||
record_cols.push(format!("{}_{}", parent_column_name, col));
|
||||
record_cols.push(format!("{parent_column_name}_{col}"));
|
||||
} else {
|
||||
record_cols.push(col.to_string());
|
||||
}
|
||||
@ -375,7 +375,7 @@ fn flat_value(columns: &[CellPath], item: &Value, _name_tag: Span, all: bool) ->
|
||||
if index == parent_column_index {
|
||||
for (col, val) in inner_cols.iter().zip(inner_vals.iter()) {
|
||||
if record_cols.contains(col) {
|
||||
record_cols.push(format!("{}_{}", parent_column_name, col));
|
||||
record_cols.push(format!("{parent_column_name}_{col}"));
|
||||
} else {
|
||||
record_cols.push(col.to_string());
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ fn extract_headers(value: &Value, config: &Config) -> Result<Vec<String>, ShellE
|
||||
.map(|(idx, value)| {
|
||||
let col = value.into_string("", config);
|
||||
if col.is_empty() {
|
||||
format!("column{}", idx)
|
||||
format!("column{idx}")
|
||||
} else {
|
||||
col
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ pub fn rotate(
|
||||
let mut new_column_names = {
|
||||
let mut res = vec![];
|
||||
for idx in 0..(*total_rows + 1) {
|
||||
res.push(format!("column{}", idx));
|
||||
res.push(format!("column{idx}"));
|
||||
}
|
||||
res.to_vec()
|
||||
};
|
||||
|
@ -80,7 +80,7 @@ impl Command for Skip {
|
||||
let n: usize = match n {
|
||||
Some(Value::Int { val, span }) => val.try_into().map_err(|err| {
|
||||
ShellError::TypeMismatch(
|
||||
format!("Could not convert {} to unsigned integer: {}", val, err),
|
||||
format!("Could not convert {val} to unsigned integer: {err}"),
|
||||
span,
|
||||
)
|
||||
})?,
|
||||
|
@ -231,7 +231,7 @@ pub fn transpose(
|
||||
if let Some(name) = args.rest.get(i) {
|
||||
headers.push(name.item.clone())
|
||||
} else {
|
||||
headers.push(format!("column{}", i));
|
||||
headers.push(format!("column{i}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ fn from_delimited_string_to_value(
|
||||
|
||||
let headers = if noheaders {
|
||||
(1..=reader.headers()?.len())
|
||||
.map(|i| format!("column{}", i))
|
||||
.map(|i| format!("column{i}"))
|
||||
.collect::<Vec<String>>()
|
||||
} else {
|
||||
reader.headers()?.iter().map(String::from).collect()
|
||||
|
@ -113,7 +113,7 @@ fn from_ics(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
|
||||
Ok(c) => output.push(calendar_to_value(c, head)),
|
||||
Err(e) => output.push(Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
format!("input cannot be parsed as .ics ({})", e),
|
||||
format!("input cannot be parsed as .ics ({e})"),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
|
@ -77,7 +77,7 @@ pub fn from_ini_string_to_value(
|
||||
Ok(Value::Record { cols, vals, span })
|
||||
}
|
||||
Err(err) => Err(ShellError::UnsupportedInput(
|
||||
format!("Could not load ini: {}", err),
|
||||
format!("Could not load ini: {err}"),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
val_span,
|
||||
|
@ -183,7 +183,7 @@ fn convert_string_to_value(string_input: String, span: Span) -> Result<Value, Sh
|
||||
))
|
||||
}
|
||||
x => Err(ShellError::CantConvert(
|
||||
format!("structured json data ({})", x),
|
||||
format!("structured json data ({x})"),
|
||||
"string".into(),
|
||||
span,
|
||||
None,
|
||||
|
@ -149,7 +149,7 @@ fn from_ods(
|
||||
_ => Value::nothing(head),
|
||||
};
|
||||
|
||||
row_output.insert(format!("column{}", i), value);
|
||||
row_output.insert(format!("column{i}"), value);
|
||||
}
|
||||
|
||||
let (cols, vals) =
|
||||
|
@ -197,7 +197,7 @@ fn parse_separated_columns<'a>(
|
||||
let num_columns = ls.iter().map(|r| r.len()).max().unwrap_or(0);
|
||||
|
||||
let headers = (1..=num_columns)
|
||||
.map(|i| format!("column{}", i))
|
||||
.map(|i| format!("column{i}"))
|
||||
.collect::<Vec<String>>();
|
||||
collect(headers, ls.into_iter(), separator)
|
||||
};
|
||||
|
@ -123,7 +123,7 @@ fn from_vcf(input: PipelineData, head: Span) -> Result<PipelineData, ShellError>
|
||||
Ok(c) => contact_to_value(c, head),
|
||||
Err(e) => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
format!("input cannot be parsed as .vcf ({})", e),
|
||||
format!("input cannot be parsed as .vcf ({e})"),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
span,
|
||||
|
@ -148,7 +148,7 @@ fn from_xlsx(
|
||||
_ => Value::nothing(head),
|
||||
};
|
||||
|
||||
row_output.insert(format!("column{}", i), value);
|
||||
row_output.insert(format!("column{i}"), value);
|
||||
}
|
||||
|
||||
let (cols, vals) =
|
||||
|
@ -120,7 +120,7 @@ fn convert_yaml_value_to_nu_value(
|
||||
for (k, v) in t {
|
||||
// A ShellError that we re-use multiple times in the Mapping scenario
|
||||
let err_unexpected_map = ShellError::UnsupportedInput(
|
||||
format!("Unexpected YAML:\nKey: {:?}\nValue: {:?}", k, v),
|
||||
format!("Unexpected YAML:\nKey: {k:?}\nValue: {v:?}"),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
val_span,
|
||||
@ -189,7 +189,7 @@ pub fn from_yaml_string_to_value(
|
||||
for document in serde_yaml::Deserializer::from_str(&s) {
|
||||
let v: serde_yaml::Value = serde_yaml::Value::deserialize(document).map_err(|x| {
|
||||
ShellError::UnsupportedInput(
|
||||
format!("Could not load YAML: {}", x),
|
||||
format!("Could not load YAML: {x}"),
|
||||
"value originates from here".into(),
|
||||
span,
|
||||
val_span,
|
||||
|
@ -55,7 +55,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
Value::Binary { val, .. } => {
|
||||
let mut s = String::with_capacity(2 * val.len());
|
||||
for byte in val {
|
||||
if write!(s, "{:02X}", byte).is_err() {
|
||||
if write!(s, "{byte:02X}").is_err() {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"could not convert binary to string".into(),
|
||||
"value originates from here".into(),
|
||||
@ -64,7 +64,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(format!("0x[{}]", s))
|
||||
Ok(format!("0x[{s}]"))
|
||||
}
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput(
|
||||
"blocks are currently not nuon-compatible".into(),
|
||||
@ -125,7 +125,7 @@ pub fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
.iter()
|
||||
.map(|string| {
|
||||
if needs_quotes(string) {
|
||||
format!("\"{}\"", string)
|
||||
format!("\"{string}\"")
|
||||
} else {
|
||||
string.to_string()
|
||||
}
|
||||
|
@ -143,13 +143,13 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
|
||||
.join(separator),
|
||||
Value::LazyRecord { val, .. } => match val.collect() {
|
||||
Ok(val) => local_into_string(val, separator, config),
|
||||
Err(error) => format!("{:?}", error),
|
||||
Err(error) => format!("{error:?}"),
|
||||
},
|
||||
Value::Block { val, .. } => format!("<Block {}>", val),
|
||||
Value::Closure { val, .. } => format!("<Closure {}>", val),
|
||||
Value::Block { val, .. } => format!("<Block {val}>"),
|
||||
Value::Closure { val, .. } => format!("<Closure {val}>"),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{:?}", error),
|
||||
Value::Binary { val, .. } => format!("{:?}", val),
|
||||
Value::Error { error } => format!("{error:?}"),
|
||||
Value::Binary { val, .. } => format!("{val:?}"),
|
||||
Value::CellPath { val, .. } => val.into_string(),
|
||||
Value::CustomValue { val, .. } => val.value_string(),
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ where
|
||||
}
|
||||
} else {
|
||||
Value::String {
|
||||
val: format!("{:x}", digest),
|
||||
val: format!("{digest:x}"),
|
||||
span,
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ fn tutor(
|
||||
|
||||
let message = format!(
|
||||
"You can find '{find}' in the following topics:\n\n{}\n\n{notes}",
|
||||
results.into_iter().map(|x| format!("- {}", x)).join("\n")
|
||||
results.into_iter().map(|x| format!("- {x}")).join("\n")
|
||||
);
|
||||
|
||||
return Ok(display(&message, engine_state, stack, span));
|
||||
@ -126,7 +126,7 @@ fn tutor(
|
||||
let results = search_space.map(|s| s.0[0].to_string());
|
||||
let message = format!(
|
||||
"This tutorial contains the following topics:\n\n{}\n\n{notes}",
|
||||
results.map(|x| format!("- {}", x)).join("\n")
|
||||
results.map(|x| format!("- {x}")).join("\n")
|
||||
);
|
||||
return Ok(display(&message, engine_state, stack, span));
|
||||
}
|
||||
|
@ -167,17 +167,17 @@ fn helper(
|
||||
let login = match (user, password) {
|
||||
(Some(user), Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:{}", user, password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(Some(user), _) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:", user), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(_, Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!(":{}", password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!(":{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
_ => None,
|
||||
@ -200,7 +200,7 @@ fn helper(
|
||||
}
|
||||
|
||||
if let Some(login) = login {
|
||||
request = request.header("Authorization", format!("Basic {}", login));
|
||||
request = request.header("Authorization", format!("Basic {login}"));
|
||||
}
|
||||
|
||||
if let Some(headers) = headers {
|
||||
@ -268,7 +268,7 @@ fn helper(
|
||||
})?;
|
||||
let content_type = mime::Mime::from_str(content_type).map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("MIME type unknown: {}", content_type),
|
||||
format!("MIME type unknown: {content_type}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("given unknown MIME type".to_string()),
|
||||
@ -280,7 +280,7 @@ fn helper(
|
||||
let path_extension = url::Url::parse(&requested_url)
|
||||
.map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("Cannot parse URL: {}", requested_url),
|
||||
format!("Cannot parse URL: {requested_url}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("cannot parse".to_string()),
|
||||
@ -307,7 +307,7 @@ fn helper(
|
||||
}
|
||||
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("from {}", ext).as_bytes(), &[]) {
|
||||
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
|
||||
Some(converter_id) => engine_state.get_decl(converter_id).run(
|
||||
engine_state,
|
||||
stack,
|
||||
@ -323,28 +323,25 @@ fn helper(
|
||||
None => Ok(response_to_buffer(resp, engine_state, span)),
|
||||
},
|
||||
Err(e) if e.is_timeout() => Err(ShellError::NetworkFailure(
|
||||
format!("Request to {} has timed out", requested_url),
|
||||
format!("Request to {requested_url} has timed out"),
|
||||
span,
|
||||
)),
|
||||
Err(e) if e.is_status() => match e.status() {
|
||||
Some(err_code) if err_code == StatusCode::NOT_FOUND => Err(ShellError::NetworkFailure(
|
||||
format!("Requested file not found (404): {:?}", requested_url),
|
||||
format!("Requested file not found (404): {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
Some(err_code) if err_code == StatusCode::MOVED_PERMANENTLY => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Resource moved permanently (301): {:?}", requested_url),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Bad request (400) to {:?}", requested_url),
|
||||
format!("Resource moved permanently (301): {requested_url:?}"),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => Err(
|
||||
ShellError::NetworkFailure(format!("Bad request (400) to {requested_url:?}"), span),
|
||||
),
|
||||
Some(err_code) if err_code == StatusCode::FORBIDDEN => Err(ShellError::NetworkFailure(
|
||||
format!("Access forbidden (403) to {:?}", requested_url),
|
||||
format!("Access forbidden (403) to {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
_ => Err(ShellError::NetworkFailure(
|
||||
|
@ -174,7 +174,7 @@ fn helper(
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
|
||||
.to_string(),
|
||||
format!("value: '{:?}'", requested_url),
|
||||
format!("value: '{requested_url:?}'"),
|
||||
call.head,
|
||||
span,
|
||||
));
|
||||
@ -190,12 +190,12 @@ fn helper(
|
||||
let login = match (user, password) {
|
||||
(Some(user), Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:{}", user, password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(Some(user), _) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:", user), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
_ => None,
|
||||
@ -249,7 +249,7 @@ fn helper(
|
||||
request = request.header("Content-Length", val);
|
||||
}
|
||||
if let Some(login) = login {
|
||||
request = request.header("Authorization", format!("Basic {}", login));
|
||||
request = request.header("Authorization", format!("Basic {login}"));
|
||||
}
|
||||
|
||||
if let Some(headers) = headers {
|
||||
@ -317,7 +317,7 @@ fn helper(
|
||||
})?;
|
||||
let content_type = mime::Mime::from_str(content_type).map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("MIME type unknown: {}", content_type),
|
||||
format!("MIME type unknown: {content_type}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("given unknown MIME type".to_string()),
|
||||
@ -329,7 +329,7 @@ fn helper(
|
||||
let path_extension = url::Url::parse(&requested_url)
|
||||
.map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("Cannot parse URL: {}", requested_url),
|
||||
format!("Cannot parse URL: {requested_url}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("cannot parse".to_string()),
|
||||
@ -354,7 +354,7 @@ fn helper(
|
||||
return Ok(output);
|
||||
}
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("from {}", ext).as_bytes(), &[]) {
|
||||
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
|
||||
Some(converter_id) => engine_state.get_decl(converter_id).run(
|
||||
engine_state,
|
||||
stack,
|
||||
@ -371,23 +371,20 @@ fn helper(
|
||||
},
|
||||
Err(e) if e.is_status() => match e.status() {
|
||||
Some(err_code) if err_code == StatusCode::NOT_FOUND => Err(ShellError::NetworkFailure(
|
||||
format!("Requested file not found (404): {:?}", requested_url),
|
||||
format!("Requested file not found (404): {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
Some(err_code) if err_code == StatusCode::MOVED_PERMANENTLY => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Resource moved permanently (301): {:?}", requested_url),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Bad request (400) to {:?}", requested_url),
|
||||
format!("Resource moved permanently (301): {requested_url:?}"),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => Err(
|
||||
ShellError::NetworkFailure(format!("Bad request (400) to {requested_url:?}"), span),
|
||||
),
|
||||
Some(err_code) if err_code == StatusCode::FORBIDDEN => Err(ShellError::NetworkFailure(
|
||||
format!("Access forbidden (403) to {:?}", requested_url),
|
||||
format!("Access forbidden (403) to {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
_ => Err(ShellError::NetworkFailure(
|
||||
|
@ -180,21 +180,21 @@ impl UrlComponents {
|
||||
.iter()
|
||||
.zip(vals.iter())
|
||||
.map(|(k, v)| match v.as_string() {
|
||||
Ok(val) => Ok(format!("{}={}", k, val)),
|
||||
Ok(val) => Ok(format!("{k}={val}")),
|
||||
Err(err) => Err(err),
|
||||
})
|
||||
.collect::<Result<Vec<String>, ShellError>>()?
|
||||
.join("&");
|
||||
|
||||
qs = format!("?{}", qs);
|
||||
qs = format!("?{qs}");
|
||||
|
||||
if let Some(q) = self.query {
|
||||
if q != qs {
|
||||
// if query is present it means that also query_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, qs from params is: {}", qs),
|
||||
left_message: format!("Mismatch, qs from params is: {qs}"),
|
||||
left_span: value.expect_span(),
|
||||
right_message: format!("instead query is: {}", q),
|
||||
right_message: format!("instead query is: {q}"),
|
||||
right_span: self.query_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
}
|
||||
@ -241,7 +241,7 @@ impl UrlComponents {
|
||||
path: Some(if s.starts_with('/') {
|
||||
s
|
||||
} else {
|
||||
format!("/{}", s)
|
||||
format!("/{s}")
|
||||
}),
|
||||
..self
|
||||
}),
|
||||
@ -250,16 +250,16 @@ impl UrlComponents {
|
||||
if q != s {
|
||||
// if query is present it means that also params_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, query param is: {}", s),
|
||||
left_message: format!("Mismatch, query param is: {s}"),
|
||||
left_span: value.expect_span(),
|
||||
right_message: format!("instead qs from params is: {}", q),
|
||||
right_message: format!("instead qs from params is: {q}"),
|
||||
right_span: self.params_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
query: Some(format!("?{}", s)),
|
||||
query: Some(format!("?{s}")),
|
||||
query_span: Some(value.expect_span()),
|
||||
..self
|
||||
})
|
||||
@ -268,7 +268,7 @@ impl UrlComponents {
|
||||
fragment: Some(if s.starts_with('#') {
|
||||
s
|
||||
} else {
|
||||
format!("#{}", s)
|
||||
format!("#{s}")
|
||||
}),
|
||||
..self
|
||||
}),
|
||||
@ -285,7 +285,7 @@ impl UrlComponents {
|
||||
|
||||
if let Some(usr) = &self.username {
|
||||
if let Some(pwd) = &self.password {
|
||||
user_and_pwd = format!("{}:{}@", usr, pwd);
|
||||
user_and_pwd = format!("{usr}:{pwd}@");
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ impl UrlComponents {
|
||||
user_and_pwd,
|
||||
host_result?,
|
||||
self.port
|
||||
.map(|p| format!(":{}", p))
|
||||
.map(|p| format!(":{p}"))
|
||||
.as_deref()
|
||||
.unwrap_or_default(),
|
||||
self.path.as_deref().unwrap_or_default(),
|
||||
|
@ -233,8 +233,7 @@ fn merge_record(
|
||||
let allowed_cols = super::ALLOWED_COLUMNS.join(", ");
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
format!(
|
||||
"Column '{}' is not valid for a structured path. Allowed columns on this platform are: {}",
|
||||
key, allowed_cols
|
||||
"Column '{key}' is not valid for a structured path. Allowed columns on this platform are: {allowed_cols}"
|
||||
),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
|
@ -682,13 +682,13 @@ Format: #
|
||||
}
|
||||
|
||||
let output = if escape && param_is_valid_string {
|
||||
format!("\x1b[{}", code_string)
|
||||
format!("\x1b[{code_string}")
|
||||
} else if osc && param_is_valid_string {
|
||||
// Operating system command aka osc ESC ] <- note the right brace, not left brace for osc
|
||||
// OCS's need to end with either:
|
||||
// bel '\x07' char
|
||||
// string terminator aka st '\\' char
|
||||
format!("\x1b]{}", code_string)
|
||||
format!("\x1b]{code_string}")
|
||||
} else if param_is_valid_string {
|
||||
// parse hex colors like #00FF00
|
||||
if code_string.starts_with('#') {
|
||||
@ -700,7 +700,7 @@ Format: #
|
||||
Err(err) => {
|
||||
return Err(ShellError::GenericError(
|
||||
"error parsing hex color".to_string(),
|
||||
format!("{}", err),
|
||||
format!("{err}"),
|
||||
Some(code.span()?),
|
||||
None,
|
||||
Vec::new(),
|
||||
@ -738,7 +738,7 @@ Format: #
|
||||
"attr" => nu_style.attr = Some(v.as_string()?),
|
||||
_ => {
|
||||
return Err(ShellError::IncompatibleParametersSingle(
|
||||
format!("problem with key: {}", k),
|
||||
format!("problem with key: {k}"),
|
||||
code.expect_span(),
|
||||
))
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ fn process_value(value: &Value, text: &Option<String>, command_span: &Span) -> V
|
||||
}
|
||||
|
||||
fn add_osc_link(text: &str, link: &str) -> String {
|
||||
format!("\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\", link, text)
|
||||
format!("\u{1b}]8;;{link}\u{1b}\\{text}\u{1b}]8;;\u{1b}\\")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -57,7 +57,7 @@ impl Command for Input {
|
||||
let _ = crossterm::terminal::enable_raw_mode();
|
||||
|
||||
if let Some(prompt) = prompt {
|
||||
print!("{}", prompt);
|
||||
print!("{prompt}");
|
||||
let _ = std::io::stdout().flush();
|
||||
}
|
||||
if let Some(c) = bytes_until.bytes().next() {
|
||||
@ -92,7 +92,7 @@ impl Command for Input {
|
||||
}
|
||||
} else {
|
||||
if let Some(prompt) = prompt {
|
||||
print!("{}", prompt);
|
||||
print!("{prompt}");
|
||||
let _ = std::io::stdout().flush();
|
||||
}
|
||||
|
||||
|
@ -113,10 +113,10 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||
"flags".into(),
|
||||
],
|
||||
vals: vec![
|
||||
Value::string(format!("{}", c), Span::unknown()),
|
||||
Value::string(format!("{c}"), Span::unknown()),
|
||||
Value::string(format!("{:#08x}", u32::from(c)), Span::unknown()),
|
||||
Value::string(format!("{:?}", modifiers), Span::unknown()),
|
||||
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
|
||||
Value::string(format!("{modifiers:?}"), Span::unknown()),
|
||||
Value::string(format!("{modifiers:#08b}"), Span::unknown()),
|
||||
],
|
||||
span: Span::unknown(),
|
||||
};
|
||||
@ -126,9 +126,9 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||
let record = Value::Record {
|
||||
cols: vec!["code".into(), "modifier".into(), "flags".into()],
|
||||
vals: vec![
|
||||
Value::string(format!("{:?}", code), Span::unknown()),
|
||||
Value::string(format!("{:?}", modifiers), Span::unknown()),
|
||||
Value::string(format!("{:#08b}", modifiers), Span::unknown()),
|
||||
Value::string(format!("{code:?}"), Span::unknown()),
|
||||
Value::string(format!("{modifiers:?}"), Span::unknown()),
|
||||
Value::string(format!("{modifiers:#08b}"), Span::unknown()),
|
||||
],
|
||||
span: Span::unknown(),
|
||||
};
|
||||
@ -138,7 +138,7 @@ fn print_events_helper(event: Event) -> Result<Value, ShellError> {
|
||||
} else {
|
||||
let record = Value::Record {
|
||||
cols: vec!["event".into()],
|
||||
vals: vec![Value::string(format!("{:?}", event), Span::unknown())],
|
||||
vals: vec![Value::string(format!("{event:?}"), Span::unknown())],
|
||||
span: Span::unknown(),
|
||||
};
|
||||
Ok(record)
|
||||
|
@ -93,8 +93,7 @@ fn action(
|
||||
not_valid => return Value::Error { error:ShellError::GenericError(
|
||||
"value is not an accepted character set".to_string(),
|
||||
format!(
|
||||
"{} is not a valid character-set.\nPlease use `help hash base64` to see a list of valid character sets.",
|
||||
not_valid
|
||||
"{not_valid} is not a valid character-set.\nPlease use `help hash base64` to see a list of valid character sets."
|
||||
),
|
||||
Some(config_character_set.span),
|
||||
None,
|
||||
|
@ -62,8 +62,7 @@ fn parse_encoding(span: Span, label: &str) -> Result<&'static Encoding, ShellErr
|
||||
match Encoding::for_label_no_replacement(label.as_bytes()) {
|
||||
None => Err(ShellError::GenericError(
|
||||
format!(
|
||||
r#"{} is not a valid encoding"#,
|
||||
label
|
||||
r#"{label} is not a valid encoding"#
|
||||
),
|
||||
"invalid encoding".into(),
|
||||
Some(span),
|
||||
|
@ -303,7 +303,7 @@ fn format_record(
|
||||
}
|
||||
Some(err) => {
|
||||
return Err(ShellError::TypeMismatch(
|
||||
format!("expression is invalid, detail message: {:?}", err),
|
||||
format!("expression is invalid, detail message: {err:?}"),
|
||||
*span,
|
||||
))
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ impl fmt::Display for Counter {
|
||||
Counter::CodePoints => "codepoints",
|
||||
};
|
||||
|
||||
write!(f, "{}", s)
|
||||
write!(f, "{s}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,10 +266,10 @@ fn trim(s: &str, char_: Option<char>, closure_flags: &ClosureFlags) -> String {
|
||||
'\x0B' => r"\v".to_string(),
|
||||
'\x0C' => r"\f".to_string(),
|
||||
'\x0D' => r"\r".to_string(),
|
||||
_ => format!(r"\{}", r),
|
||||
_ => format!(r"\{r}"),
|
||||
};
|
||||
// create a regex string that looks for 2 or more of each of these characters
|
||||
let re_str = format!("{}{{2,}}", reg);
|
||||
let re_str = format!("{reg}{{2,}}");
|
||||
// create the regex
|
||||
let re = Regex::new(&re_str).expect("Error creating regular expression");
|
||||
// replace all multiple occurrences with single occurrences represented by r
|
||||
|
@ -753,7 +753,7 @@ fn shell_arg_escape(arg: &str) -> String {
|
||||
s if !has_unsafe_shell_characters(s) => String::from(s),
|
||||
_ => {
|
||||
let single_quotes_escaped = arg.split('\'').join("'\"'\"'");
|
||||
format!("'{}'", single_quotes_escaped)
|
||||
format!("'{single_quotes_escaped}'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ fn get_entry_in_aliases(engine_state: &EngineState, name: &str, span: Span) -> O
|
||||
|
||||
Some(entry(
|
||||
name,
|
||||
format!("Nushell alias: {}", alias_str),
|
||||
format!("Nushell alias: {alias_str}"),
|
||||
false,
|
||||
span,
|
||||
))
|
||||
|
@ -239,7 +239,7 @@ fn create_grid_output(
|
||||
Value::string(grid_display.to_string(), call.head)
|
||||
} else {
|
||||
Value::String {
|
||||
val: format!("Couldn't fit grid into {} columns!", cols),
|
||||
val: format!("Couldn't fit grid into {cols} columns!"),
|
||||
span: call.head,
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ fn handle_table_command(
|
||||
} else {
|
||||
// assume this failed because the table was too wide
|
||||
// TODO: more robust error classification
|
||||
format!("Couldn't fit table into {} columns!", term_width)
|
||||
format!("Couldn't fit table into {term_width} columns!")
|
||||
}
|
||||
});
|
||||
|
||||
@ -1481,7 +1481,7 @@ fn convert_with_precision(val: &str, precision: usize) -> Result<String, ShellEr
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(format!("{:.prec$}", val_float, prec = precision))
|
||||
Ok(format!("{val_float:.precision$}"))
|
||||
}
|
||||
|
||||
fn is_cfg_trim_keep_words(config: &Config) -> bool {
|
||||
@ -1696,7 +1696,7 @@ impl Iterator for PagingTableCreator {
|
||||
// assume this failed because the table was too wide
|
||||
// TODO: more robust error classification
|
||||
let term_width = get_width_param(self.width_param);
|
||||
format!("Couldn't fit table into {} columns!", term_width)
|
||||
format!("Couldn't fit table into {term_width} columns!")
|
||||
};
|
||||
Some(Ok(msg.as_bytes().to_vec()))
|
||||
}
|
||||
|
Reference in New Issue
Block a user