Add size units to parsing

This commit is contained in:
Jonathan Turner 2019-05-28 17:05:14 +12:00
parent 420b840cd6
commit 10702cd27f
6 changed files with 315 additions and 211 deletions

View File

@ -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)),

View File

@ -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;

View File

@ -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"));
}

View File

@ -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)),

View File

@ -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