mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
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:
parent
f8bb0c99ec
commit
5d4097073b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1079,6 +1079,7 @@ dependencies = [
|
|||||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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-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)",
|
"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)",
|
"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)",
|
"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)",
|
"derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -47,6 +47,7 @@ language-reporting = "0.3.0"
|
|||||||
app_dirs = "1.2.1"
|
app_dirs = "1.2.1"
|
||||||
toml = "0.5.1"
|
toml = "0.5.1"
|
||||||
toml-query = "0.9.0"
|
toml-query = "0.9.0"
|
||||||
|
clap = "2.33.0"
|
||||||
|
|
||||||
[dependencies.pancurses]
|
[dependencies.pancurses]
|
||||||
version = "0.16"
|
version = "0.16"
|
||||||
|
@ -16,6 +16,11 @@ command = "cargo"
|
|||||||
args = ["run", "--release"]
|
args = ["run", "--release"]
|
||||||
dependencies = ["baseline"]
|
dependencies = ["baseline"]
|
||||||
|
|
||||||
|
[tasks.release]
|
||||||
|
command = "cargo"
|
||||||
|
args = ["build", "--release"]
|
||||||
|
dependencies = ["baseline"]
|
||||||
|
|
||||||
[tasks.test]
|
[tasks.test]
|
||||||
command = "cargo"
|
command = "cargo"
|
||||||
args = ["test"]
|
args = ["test"]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::object::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
|
|
||||||
// TODO: "Amount remaining" wrapper
|
// TODO: "Amount remaining" wrapper
|
||||||
|
|
||||||
@ -13,10 +13,10 @@ pub fn split_column(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
.map(move |v| match v {
|
.map(move |v| match v {
|
||||||
Value::Primitive(Primitive::String(s)) => {
|
Value::Primitive(Primitive::String(s)) => {
|
||||||
let splitter = args[0].as_string().unwrap().replace("\\n", "\n");
|
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();
|
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 they didn't provide column names, make up our own
|
||||||
if (args.len() - 1) == 0 {
|
if (args.len() - 1) == 0 {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::object::{Primitive, Value};
|
use crate::object::{Primitive, Value};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
|
|
||||||
// TODO: "Amount remaining" wrapper
|
// TODO: "Amount remaining" wrapper
|
||||||
|
|
||||||
@ -13,14 +13,16 @@ pub fn split_row(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
.map(move |v| match v {
|
.map(move |v| match v {
|
||||||
Value::Primitive(Primitive::String(s)) => {
|
Value::Primitive(Primitive::String(s)) => {
|
||||||
let splitter = args[0].as_string().unwrap().replace("\\n", "\n");
|
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();
|
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();
|
let mut result = VecDeque::new();
|
||||||
for s in split_result {
|
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
|
result
|
||||||
}
|
}
|
||||||
|
50
src/main.rs
50
src/main.rs
@ -17,10 +17,58 @@ mod prelude;
|
|||||||
mod shell;
|
mod shell;
|
||||||
mod stream;
|
mod stream;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
|
use log::LevelFilter;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<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())?;
|
futures::executor::block_on(crate::cli::cli())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
use logos_derive::Logos;
|
use logos_derive::Logos;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
@ -114,12 +114,12 @@ impl TopToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_variable<S>(lex: &mut logos::Lexer<TopToken, S>) {
|
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;
|
lex.extras.current = LexerStateName::Var;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end_bare_variable<S>(lex: &mut logos::Lexer<TopToken, S>) {
|
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;
|
lex.extras.current = LexerStateName::AfterVariableToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ impl VariableToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn end_variable<S>(lex: &mut logos::Lexer<VariableToken, S>) {
|
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;
|
lex.extras.current = LexerStateName::AfterVariableToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,12 +190,12 @@ impl AfterVariableToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_member<S>(lex: &mut logos::Lexer<AfterVariableToken, S>) {
|
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;
|
lex.extras.current = LexerStateName::AfterMemberDot;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn terminate_variable<S>(lex: &mut logos::Lexer<AfterVariableToken, S>) {
|
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;
|
lex.extras.current = LexerStateName::Top;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ impl AfterMemberDot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finish_member<S>(lex: &mut logos::Lexer<AfterMemberDot, S>) {
|
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;
|
lex.extras.current = LexerStateName::AfterVariableToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ impl Iterator for Lexer<'source> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!("STATE={:?}", self.lexer.extras);
|
trace!("STATE={:?}", self.lexer.extras);
|
||||||
|
|
||||||
match self.lexer.extras.current {
|
match self.lexer.extras.current {
|
||||||
LexerStateName::Top => {
|
LexerStateName::Top => {
|
||||||
@ -514,7 +514,7 @@ mod tests {
|
|||||||
let expected_tokens: Vec<SpannedToken> = tokens
|
let expected_tokens: Vec<SpannedToken> = tokens
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|token_desc| {
|
.filter_map(|token_desc| {
|
||||||
debug!("{:?}", token_desc);
|
trace!("{:?}", token_desc);
|
||||||
|
|
||||||
let len = token_desc.source.len();
|
let len = token_desc.source.len();
|
||||||
let range = current..(current + len);
|
let range = current..(current + len);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// auto-generated: "lalrpop 0.17.0"
|
// auto-generated: "lalrpop 0.17.0"
|
||||||
// sha256: b26b8a2cdaceecc744b5554b038a811430dd7af761c75685fc9e389596528
|
// sha256: 87c2cd6c2bebdfcacc6ef8d0463e82c6959682b98cab66dffe6dfaf11cb41
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use crate::parser::ast::*;
|
use crate::parser::ast::*;
|
||||||
|
@ -3,7 +3,7 @@ use crate::shell::completer::NuCompleter;
|
|||||||
use crate::parser::lexer::SpannedToken;
|
use crate::parser::lexer::SpannedToken;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use log::debug;
|
use log::trace;
|
||||||
use rustyline::completion::{self, Completer, FilenameCompleter};
|
use rustyline::completion::{self, Completer, FilenameCompleter};
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::highlight::Highlighter;
|
use rustyline::highlight::Highlighter;
|
||||||
@ -73,9 +73,9 @@ impl Highlighter for Helper {
|
|||||||
Some((start, token, end)) => {
|
Some((start, token, end)) => {
|
||||||
let (style, new_state) = token_style(&token, state);
|
let (style, new_state) = token_style(&token, state);
|
||||||
|
|
||||||
debug!("token={:?}", token);
|
trace!("token={:?}", token);
|
||||||
debug!("style={:?}", style);
|
trace!("style={:?}", style);
|
||||||
debug!("new_state={:?}", new_state);
|
trace!("new_state={:?}", new_state);
|
||||||
|
|
||||||
state = new_state;
|
state = new_state;
|
||||||
let slice = &line[*start..*end];
|
let slice = &line[*start..*end];
|
||||||
|
Loading…
Reference in New Issue
Block a user