diff --git a/Cargo.lock b/Cargo.lock index ac7d546311..22c36fea44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,6 +1079,7 @@ dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "chrono-humanize 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "chrono-tz 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "conch-parser 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "cursive 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 0d0562ff99..02a59f0fd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ language-reporting = "0.3.0" app_dirs = "1.2.1" toml = "0.5.1" toml-query = "0.9.0" +clap = "2.33.0" [dependencies.pancurses] version = "0.16" diff --git a/Makefile.toml b/Makefile.toml index 9d98c7fde6..cb3060052f 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -16,6 +16,11 @@ command = "cargo" args = ["run", "--release"] dependencies = ["baseline"] +[tasks.release] +command = "cargo" +args = ["build", "--release"] +dependencies = ["baseline"] + [tasks.test] command = "cargo" args = ["test"] diff --git a/src/commands/split_column.rs b/src/commands/split_column.rs index 81b5480801..c768ec6b83 100644 --- a/src/commands/split_column.rs +++ b/src/commands/split_column.rs @@ -1,7 +1,7 @@ use crate::errors::ShellError; use crate::object::{Primitive, Value}; use crate::prelude::*; -use log::debug; +use log::trace; // TODO: "Amount remaining" wrapper @@ -13,10 +13,10 @@ pub fn split_column(args: CommandArgs) -> Result { .map(move |v| match v { Value::Primitive(Primitive::String(s)) => { let splitter = args[0].as_string().unwrap().replace("\\n", "\n"); - debug!("splitting with {:?}", splitter); + trace!("splitting with {:?}", splitter); let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect(); - debug!("split result = {:?}", split_result); + trace!("split result = {:?}", split_result); // If they didn't provide column names, make up our own if (args.len() - 1) == 0 { diff --git a/src/commands/split_row.rs b/src/commands/split_row.rs index 65d6cbe890..fead9f8e1f 100644 --- a/src/commands/split_row.rs +++ b/src/commands/split_row.rs @@ -1,7 +1,7 @@ use crate::errors::ShellError; use crate::object::{Primitive, Value}; use crate::prelude::*; -use log::debug; +use log::trace; // TODO: "Amount remaining" wrapper @@ -13,14 +13,16 @@ pub fn split_row(args: CommandArgs) -> Result { .map(move |v| match v { Value::Primitive(Primitive::String(s)) => { let splitter = args[0].as_string().unwrap().replace("\\n", "\n"); - debug!("splitting with {:?}", splitter); + trace!("splitting with {:?}", splitter); let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect(); - debug!("split result = {:?}", split_result); + trace!("split result = {:?}", split_result); let mut result = VecDeque::new(); for s in split_result { - result.push_back(ReturnValue::Value(Value::Primitive(Primitive::String(s.to_string())))); + result.push_back(ReturnValue::Value(Value::Primitive(Primitive::String( + s.to_string(), + )))); } result } diff --git a/src/main.rs b/src/main.rs index 550361cf4b..0275b34792 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,10 +17,58 @@ mod prelude; mod shell; mod stream; +use clap::{App, Arg}; +use log::LevelFilter; use std::error::Error; fn main() -> Result<(), Box> { - pretty_env_logger::init(); + let matches = App::new("nu shell") + .version("0.5") + .arg( + Arg::with_name("loglevel") + .short("l") + .long("loglevel") + .value_name("LEVEL") + .possible_values(&["error", "warn", "info", "debug", "trace"]) + .takes_value(true), + ) + .arg( + Arg::with_name("develop") + .long("develop") + .multiple(true) + .takes_value(true), + ) + .get_matches(); + + let loglevel = match matches.value_of("loglevel") { + None => LevelFilter::Warn, + Some("error") => LevelFilter::Error, + Some("warn") => LevelFilter::Warn, + Some("info") => LevelFilter::Info, + Some("debug") => LevelFilter::Debug, + Some("trace") => LevelFilter::Trace, + _ => unreachable!(), + }; + + let mut builder = pretty_env_logger::formatted_builder(); + + if let Ok(s) = std::env::var("RUST_LOG") { + builder.parse_filters(&s); + } + + builder.filter_module("nu", loglevel); + + match matches.values_of("develop") { + None => {} + Some(values) => for item in values { + println!("filtering {:?}", item); + builder.filter_module(&format!("nu::{}", item), LevelFilter::Trace); + } //println!("{:?}", values.collect::>()), + } + + builder.try_init()?; + + // pretty_env_logger::init(); futures::executor::block_on(crate::cli::cli())?; Ok(()) } diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 452b3bc14d..387ba6f04f 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -1,6 +1,6 @@ use crate::errors::ShellError; use derive_new::new; -use log::debug; +use log::trace; use logos_derive::Logos; use std::ops::Range; @@ -114,12 +114,12 @@ impl TopToken { } fn start_variable(lex: &mut logos::Lexer) { - debug!("start_variable EXTRAS={:?}", lex.extras); + trace!("start_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::Var; } fn end_bare_variable(lex: &mut logos::Lexer) { - debug!("end_variable EXTRAS={:?}", lex.extras); + trace!("end_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::AfterVariableToken; } @@ -152,7 +152,7 @@ impl VariableToken { } fn end_variable(lex: &mut logos::Lexer) { - debug!("end_variable EXTRAS={:?}", lex.extras); + trace!("end_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::AfterVariableToken; } @@ -190,12 +190,12 @@ impl AfterVariableToken { } fn start_member(lex: &mut logos::Lexer) { - debug!("start_variable EXTRAS={:?}", lex.extras); + trace!("start_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::AfterMemberDot; } fn terminate_variable(lex: &mut logos::Lexer) { - debug!("terminate_variable EXTRAS={:?}", lex.extras); + trace!("terminate_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::Top; } @@ -232,7 +232,7 @@ impl AfterMemberDot { } fn finish_member(lex: &mut logos::Lexer) { - debug!("finish_member EXTRAS={:?}", lex.extras); + trace!("finish_member EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::AfterVariableToken; } @@ -407,7 +407,7 @@ impl Iterator for Lexer<'source> { } } } else { - debug!("STATE={:?}", self.lexer.extras); + trace!("STATE={:?}", self.lexer.extras); match self.lexer.extras.current { LexerStateName::Top => { @@ -514,7 +514,7 @@ mod tests { let expected_tokens: Vec = tokens .iter() .filter_map(|token_desc| { - debug!("{:?}", token_desc); + trace!("{:?}", token_desc); let len = token_desc.source.len(); let range = current..(current + len); diff --git a/src/parser/parser.rs b/src/parser/parser.rs index b3a87beb76..63f68726fa 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.17.0" -// sha256: b26b8a2cdaceecc744b5554b038a811430dd7af761c75685fc9e389596528 +// sha256: 87c2cd6c2bebdfcacc6ef8d0463e82c6959682b98cab66dffe6dfaf11cb41 #![allow(unused)] use std::str::FromStr; use crate::parser::ast::*; diff --git a/src/shell/helper.rs b/src/shell/helper.rs index c8280186c0..c930d9fff2 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -3,7 +3,7 @@ use crate::shell::completer::NuCompleter; use crate::parser::lexer::SpannedToken; use crate::prelude::*; use ansi_term::Color; -use log::debug; +use log::trace; use rustyline::completion::{self, Completer, FilenameCompleter}; use rustyline::error::ReadlineError; use rustyline::highlight::Highlighter; @@ -73,9 +73,9 @@ impl Highlighter for Helper { Some((start, token, end)) => { let (style, new_state) = token_style(&token, state); - debug!("token={:?}", token); - debug!("style={:?}", style); - debug!("new_state={:?}", new_state); + trace!("token={:?}", token); + trace!("style={:?}", style); + trace!("new_state={:?}", new_state); state = new_state; let slice = &line[*start..*end];