Allow config to work with column paths. (#2653)

Nu has many commands that allow the nuño to customize behavior such
as UI and behavior. Today, coloring can be customized, the line editor,
and other things. The more options there are, the higher the complexity
in managing them.

To mitigate this Nu can store configuration options as nested properties.

But to add and edit them can be taxing. With column path support we can
work with them easier.
This commit is contained in:
Andrés N. Robalino
2020-10-08 20:04:19 -05:00
committed by GitHub
parent 1159d3365a
commit 973a8ee8f3
11 changed files with 361 additions and 72 deletions

View File

@@ -2,6 +2,7 @@ pub mod commands;
pub mod fs;
pub mod macros;
pub mod playground;
pub mod value;
pub fn pipeline(commands: &str) -> String {
commands

View File

@@ -0,0 +1,50 @@
use chrono::{DateTime, NaiveDate, Utc};
use indexmap::IndexMap;
use nu_errors::ShellError;
use nu_protocol::{ColumnPath, PathMember, Primitive, UntaggedValue, Value};
use nu_source::{Span, Tagged, TaggedItem};
use nu_value_ext::as_column_path;
use num_bigint::BigInt;
pub fn int(s: impl Into<BigInt>) -> Value {
UntaggedValue::int(s).into_untagged_value()
}
pub fn decimal_from_float(f: f64, span: Span) -> Value {
UntaggedValue::decimal_from_float(f, span).into_untagged_value()
}
pub fn string(input: impl Into<String>) -> Value {
UntaggedValue::string(input.into()).into_untagged_value()
}
pub fn row(entries: IndexMap<String, Value>) -> Value {
UntaggedValue::row(entries).into_untagged_value()
}
pub fn table(list: &[Value]) -> Value {
UntaggedValue::table(list).into_untagged_value()
}
pub fn date(input: impl Into<String>) -> Value {
let key = input.into().tagged_unknown();
let date = NaiveDate::parse_from_str(key.borrow_tagged().item, "%Y-%m-%d")
.expect("date from string failed");
UntaggedValue::Primitive(Primitive::Date(DateTime::<Utc>::from_utc(
date.and_hms(12, 34, 56),
Utc,
)))
.into_untagged_value()
}
pub fn column_path(paths: &[Value]) -> Result<Tagged<ColumnPath>, ShellError> {
as_column_path(&table(paths))
}
pub fn error_callback(
reason: &'static str,
) -> impl FnOnce(&Value, &PathMember, ShellError) -> ShellError {
move |_obj_source, _column_path_tried, _err| ShellError::unimplemented(reason)
}