Slim down configuration readings and nu_cli clean up. (#2559)

We continue refactoring nu_cli and slim down a bit configuration
readings with a naive metadata `modified` field check.
This commit is contained in:
Andrés N. Robalino
2020-09-16 18:22:58 -05:00
committed by GitHub
parent 50cbf91bc5
commit 10d4edc7af
12 changed files with 632 additions and 387 deletions

View File

@ -37,7 +37,7 @@ pub trait ConfigExtensions: Debug + Send {
}
pub fn pivot_mode(config: &NuConfig) -> AutoPivotMode {
let vars = config.vars.lock();
let vars = &config.vars;
if let Some(mode) = vars.get("pivot_mode") {
let mode = match mode.as_string() {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::prelude::*;
use nu_data::config::NuConfig;
use nu_data::config::{Conf, NuConfig};
use nu_errors::ShellError;
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
use std::fs::File;
@ -9,9 +9,7 @@ use std::path::PathBuf;
const DEFAULT_LOCATION: &str = "history.txt";
pub fn history_path(config: &NuConfig) -> PathBuf {
let vars = config.vars.lock();
pub fn history_path(config: &dyn Conf) -> PathBuf {
let default_path = nu_data::config::user_data()
.map(|mut p| {
p.push(DEFAULT_LOCATION);
@ -19,7 +17,8 @@ pub fn history_path(config: &NuConfig) -> PathBuf {
})
.unwrap_or_else(|_| PathBuf::from(DEFAULT_LOCATION));
vars.get("history-path")
config
.var("history-path")
.map_or(default_path.clone(), |custom_path| {
match custom_path.as_string() {
Ok(path) => PathBuf::from(path),
@ -54,7 +53,7 @@ impl WholeStreamCommand for History {
}
fn history(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let config = NuConfig::new();
let config: Box<dyn Conf> = Box::new(NuConfig::new());
let tag = args.call_info.name_tag;
let path = history_path(&config);
let file = File::open(path);

View File

@ -27,7 +27,7 @@ pub fn header_alignment_from_value(align_value: Option<&Value>) -> nu_table::Ali
}
pub fn get_color_from_key_and_subkey(config: &NuConfig, key: &str, subkey: &str) -> Option<Value> {
let vars = config.vars.lock();
let vars = &config.vars;
if let Some(config_vars) = vars.get(key) {
for (kee, value) in config_vars.row_entries() {
@ -47,7 +47,7 @@ pub fn header_bold_from_value(bold_value: Option<&Value>) -> bool {
}
pub fn table_mode(config: &NuConfig) -> nu_table::Theme {
let vars = config.vars.lock();
let vars = &config.vars;
vars.get("table_mode")
.map_or(nu_table::Theme::compact(), |mode| match mode.as_string() {
@ -62,7 +62,7 @@ pub fn table_mode(config: &NuConfig) -> nu_table::Theme {
}
pub fn disabled_indexes(config: &NuConfig) -> bool {
let vars = config.vars.lock();
let vars = &config.vars;
vars.get("disable_table_indexes")
.map_or(false, |x| x.as_bool().unwrap_or(false))