mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 09:42:24 +02:00
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:
committed by
GitHub
parent
1159d3365a
commit
973a8ee8f3
@@ -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
|
||||
|
50
crates/nu-test-support/src/value.rs
Normal file
50
crates/nu-test-support/src/value.rs
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user