mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01: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 mut allowed = Trusted::read_trusted()?;
|
||||
allowed.files.insert(
|
||||
filename,
|
||||
Sha256::digest(&content).as_slice().to_vec()
|
||||
);
|
||||
allowed
|
||||
.files
|
||||
.insert(filename, Sha256::digest(&content).as_slice().to_vec());
|
||||
|
||||
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
|
||||
let tomlstr = toml::to_string(&allowed).or_else(|_| {
|
||||
|
@ -38,11 +38,10 @@ impl DirectorySpecificEnvironment {
|
||||
if trusted.files.get(wdirenv.to_str().unwrap_or(""))
|
||||
== 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)))
|
||||
})?;
|
||||
let content = std::fs::read_to_string(&wdirenv)?;
|
||||
return Ok(content.parse::<toml::Value>().or_else(|_| {
|
||||
})?
|
||||
.parse::<toml::Value>().or_else(|_| {
|
||||
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)",
|
||||
wdirenv
|
||||
|
Loading…
Reference in New Issue
Block a user