mirror of
https://github.com/nushell/nushell.git
synced 2025-06-25 12:21:37 +02:00
Refactoring
This commit is contained in:
parent
c6bbf140ed
commit
a86438686e
@ -50,10 +50,9 @@ impl WholeStreamCommand for AutoenvTrust {
|
|||||||
|
|
||||||
let filename = file_to_trust.to_string_lossy().to_string();
|
let filename = file_to_trust.to_string_lossy().to_string();
|
||||||
let mut allowed = Trusted::read_trusted()?;
|
let mut allowed = Trusted::read_trusted()?;
|
||||||
allowed.files.insert(
|
allowed
|
||||||
filename,
|
.files
|
||||||
Sha256::digest(&content).as_slice().to_vec()
|
.insert(filename, Sha256::digest(&content).as_slice().to_vec());
|
||||||
);
|
|
||||||
|
|
||||||
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
||||||
let tomlstr = toml::to_string(&allowed).or_else(|_| {
|
let tomlstr = toml::to_string(&allowed).or_else(|_| {
|
||||||
|
@ -38,11 +38,10 @@ impl DirectorySpecificEnvironment {
|
|||||||
if trusted.files.get(wdirenv.to_str().unwrap_or(""))
|
if trusted.files.get(wdirenv.to_str().unwrap_or(""))
|
||||||
== Some(&Sha256::digest(&content).as_slice().to_vec())
|
== Some(&Sha256::digest(&content).as_slice().to_vec())
|
||||||
{
|
{
|
||||||
let content = std::str::from_utf8(&content.as_slice()).or_else(|_| {
|
return Ok(std::str::from_utf8(&content.as_slice()).or_else(|_| {
|
||||||
Err(ShellError::untagged_runtime_error(format!("Could not read {:?} as utf8 string", content)))
|
Err(ShellError::untagged_runtime_error(format!("Could not read {:?} as utf8 string", content)))
|
||||||
})?;
|
})?
|
||||||
let content = std::fs::read_to_string(&wdirenv)?;
|
.parse::<toml::Value>().or_else(|_| {
|
||||||
return Ok(content.parse::<toml::Value>().or_else(|_| {
|
|
||||||
Err(ShellError::untagged_runtime_error(format!(
|
Err(ShellError::untagged_runtime_error(format!(
|
||||||
"Could not parse {:?}. Is it well-formed? Each entry must be written as key = \"value\" (note the quotation marks)",
|
"Could not parse {:?}. Is it well-formed? Each entry must be written as key = \"value\" (note the quotation marks)",
|
||||||
wdirenv
|
wdirenv
|
||||||
|
Loading…
x
Reference in New Issue
Block a user