Add --loglevel and --develop

--loglevel sets the log level for all of nu
--develop takes a list of modules and turns on trace mode for them
This commit is contained in:
Yehuda Katz 2019-06-01 10:00:42 -07:00
parent f8bb0c99ec
commit 5d4097073b
9 changed files with 79 additions and 22 deletions

1
Cargo.lock generated
View File

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

View File

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

View File

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

View File

@ -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<OutputStream, ShellError> {
.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 {

View File

@ -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<OutputStream, ShellError> {
.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
}

View File

@ -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<Error>> {
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::<Vec<&str>>()),
}
builder.try_init()?;
// pretty_env_logger::init();
futures::executor::block_on(crate::cli::cli())?;
Ok(())
}

View File

@ -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<S>(lex: &mut logos::Lexer<TopToken, S>) {
debug!("start_variable EXTRAS={:?}", lex.extras);
trace!("start_variable EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::Var;
}
fn end_bare_variable<S>(lex: &mut logos::Lexer<TopToken, S>) {
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<S>(lex: &mut logos::Lexer<VariableToken, S>) {
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<S>(lex: &mut logos::Lexer<AfterVariableToken, S>) {
debug!("start_variable EXTRAS={:?}", lex.extras);
trace!("start_variable EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::AfterMemberDot;
}
fn terminate_variable<S>(lex: &mut logos::Lexer<AfterVariableToken, S>) {
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<S>(lex: &mut logos::Lexer<AfterMemberDot, S>) {
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<SpannedToken> = tokens
.iter()
.filter_map(|token_desc| {
debug!("{:?}", token_desc);
trace!("{:?}", token_desc);
let len = token_desc.source.len();
let range = current..(current + len);

View File

@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.17.0"
// sha256: b26b8a2cdaceecc744b5554b038a811430dd7af761c75685fc9e389596528
// sha256: 87c2cd6c2bebdfcacc6ef8d0463e82c6959682b98cab66dffe6dfaf11cb41
#![allow(unused)]
use std::str::FromStr;
use crate::parser::ast::*;

View File

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