mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Add size units to parsing
This commit is contained in:
parent
420b840cd6
commit
10702cd27f
@ -51,7 +51,7 @@ pub async fn cli() -> Result<(), Box<Error>> {
|
||||
("size", Arc::new(size::size)),
|
||||
("from-json", Arc::new(from_json::from_json)),
|
||||
("open", Arc::new(open::open)),
|
||||
("column", Arc::new(select::select)),
|
||||
("column", Arc::new(column::column)),
|
||||
("split", Arc::new(split::split)),
|
||||
("reject", Arc::new(reject::reject)),
|
||||
("to-array", Arc::new(to_array::to_array)),
|
||||
|
@ -1,13 +1,13 @@
|
||||
crate mod args;
|
||||
crate mod cd;
|
||||
crate mod classified;
|
||||
crate mod column;
|
||||
crate mod command;
|
||||
crate mod from_json;
|
||||
crate mod ls;
|
||||
crate mod open;
|
||||
crate mod ps;
|
||||
crate mod reject;
|
||||
crate mod select;
|
||||
crate mod size;
|
||||
crate mod skip;
|
||||
crate mod sort_by;
|
||||
|
@ -3,7 +3,7 @@ use crate::object::base::select_fields;
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn select(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
pub fn column(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
if args.args.is_empty() {
|
||||
return Err(ShellError::string("select requires a field"));
|
||||
}
|
@ -54,7 +54,7 @@ impl Primitive {
|
||||
return Color::Black.bold().paint("Empty".to_string()).to_string();
|
||||
}
|
||||
|
||||
let byte = byte.get_appropriate_unit(true);
|
||||
let byte = byte.get_appropriate_unit(false);
|
||||
|
||||
match byte.get_unit() {
|
||||
byte_unit::ByteUnit::B => format!("{}", byte.format(0)),
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
use crate::parser::tokens::*;
|
||||
use byte_unit::Byte;
|
||||
|
||||
grammar;
|
||||
|
||||
@ -42,6 +43,7 @@ String: String = {
|
||||
|
||||
Leaf: Leaf = {
|
||||
<String> => Leaf::String(<>),
|
||||
<Size> => Leaf::Int(<>),
|
||||
<Num> => Leaf::Int(<>),
|
||||
<RawBareWord> => match <>.as_ref() {
|
||||
"true" => Leaf::Boolean(true),
|
||||
@ -54,3 +56,4 @@ RawBareWord: String = <s:r#"[^0-9"'\-][^\s]*"#> => <>.to_string();
|
||||
DQString: String = <s:r#""([^"]|\\")*""#> => s[1..s.len() - 1].to_string();
|
||||
SQString: String = <s:r#"'([^']|\\')*'"#> => s[1..s.len() - 1].to_string();
|
||||
Num: i64 = <s:r"-?[0-9]+"> => i64::from_str(s).unwrap();
|
||||
Size: i64 = <s:r"-?[0-9]+[A-Za-z]+"> => Byte::from_string(s).unwrap().get_bytes() as i64;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user