summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/compilers/ts.rs4
-rw-r--r--cli/file_fetcher.rs6
-rw-r--r--cli/flags.rs41
-rw-r--r--cli/lib.rs15
-rw-r--r--cli/permissions.rs11
5 files changed, 48 insertions, 29 deletions
diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs
index f2c8e41fe..4f822dc2c 100644
--- a/cli/compilers/ts.rs
+++ b/cli/compilers/ts.rs
@@ -22,6 +22,7 @@ use deno_core::Buf;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use futures::future::FutureExt;
+use log::info;
use regex::Regex;
use serde_json::json;
use std::collections::HashMap;
@@ -373,11 +374,12 @@ impl TsCompiler {
let ts_compiler = self.clone();
- eprintln!(
+ info!(
"{} {}",
colors::green("Compile".to_string()),
module_url.to_string()
);
+
let msg = execute_in_thread(global_state.clone(), req_msg).await?;
let json_str = std::str::from_utf8(&msg).unwrap();
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index c3a576df5..af512916d 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -9,9 +9,9 @@ use crate::op_error::OpError;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use futures::future::FutureExt;
+use log::info;
use regex::Regex;
use reqwest;
-use std;
use std::collections::HashMap;
use std::fs;
use std::future::Future;
@@ -23,7 +23,6 @@ use std::result::Result;
use std::str;
use std::sync::Arc;
use std::sync::Mutex;
-use url;
use url::Url;
/// Structure representing local or remote file.
@@ -414,11 +413,12 @@ impl SourceFileFetcher {
.boxed_local();
}
- eprintln!(
+ info!(
"{} {}",
colors::green("Download".to_string()),
module_url.to_string()
);
+
let dir = self.clone();
let module_url = module_url.clone();
let module_etag = match self.http_cache.get(&module_url) {
diff --git a/cli/flags.rs b/cli/flags.rs
index f5a6f0dfd..ccf75c9fc 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -59,7 +59,6 @@ pub enum DenoSubcommand {
},
Test {
fail_fast: bool,
- quiet: bool,
allow_none: bool,
include: Option<Vec<String>>,
},
@@ -231,6 +230,9 @@ pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<Flags> {
_ => unreachable!(),
};
}
+ if matches.is_present("quiet") {
+ flags.log_level = Some(Level::Error);
+ }
if let Some(m) = matches.subcommand_matches("run") {
run_parse(&mut flags, m);
@@ -283,6 +285,18 @@ fn clap_root<'a, 'b>() -> App<'a, 'b> {
.possible_values(&["debug", "info"])
.global(true),
)
+ .arg(
+ Arg::with_name("quiet")
+ .short("q")
+ .long("quiet")
+ .help("Suppress diagnostic output")
+ .long_help(
+ "Suppress diagnostic output
+By default, subcommands print human-readable diagnostic messages to stderr.
+If the flag is set, restrict these messages to errors.",
+ )
+ .global(true),
+ )
.subcommand(bundle_subcommand())
.subcommand(completions_subcommand())
.subcommand(eval_subcommand())
@@ -505,7 +519,6 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
run_test_args_parse(flags, matches);
- let quiet = matches.is_present("quiet");
let failfast = matches.is_present("failfast");
let allow_none = matches.is_present("allow_none");
@@ -521,7 +534,6 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
};
flags.subcommand = DenoSubcommand::Test {
- quiet,
fail_fast: failfast,
include,
allow_none,
@@ -867,13 +879,6 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
.takes_value(false),
)
.arg(
- Arg::with_name("quiet")
- .short("q")
- .long("quiet")
- .help("Don't show output from test cases")
- .takes_value(false),
- )
- .arg(
Arg::with_name("allow_none")
.long("allow-none")
.help("Don't return error code if no test files are found")
@@ -1948,6 +1953,21 @@ mod tests {
}
#[test]
+ fn quiet() {
+ let r = flags_from_vec_safe(svec!["deno", "-q", "script.ts"]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Run {
+ script: "script.ts".to_string(),
+ },
+ log_level: Some(Level::Error),
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn completions() {
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]).unwrap();
@@ -2109,7 +2129,6 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Test {
fail_fast: false,
- quiet: false,
allow_none: true,
include: Some(svec!["dir1/", "dir2/"]),
},
diff --git a/cli/lib.rs b/cli/lib.rs
index a4d4ec331..3e3641929 100644
--- a/cli/lib.rs
+++ b/cli/lib.rs
@@ -81,6 +81,7 @@ use url::Url;
static LOGGER: Logger = Logger;
+// TODO(ry) Switch to env_logger or other standard crate.
struct Logger;
impl log::Log for Logger {
@@ -97,7 +98,11 @@ impl log::Log for Logger {
target.push_str(&line_no.to_string());
}
- println!("{} RS - {} - {}", record.level(), target, record.args());
+ if record.level() >= Level::Info {
+ eprintln!("{}", record.args());
+ } else {
+ eprintln!("{} RS - {} - {}", record.level(), target, record.args());
+ }
}
}
fn flush(&self) {}
@@ -372,7 +377,6 @@ async fn test_command(
flags: Flags,
include: Option<Vec<String>>,
fail_fast: bool,
- _quiet: bool,
allow_none: bool,
) -> Result<(), ErrBox> {
let global_state = GlobalState::new(flags.clone())?;
@@ -427,7 +431,7 @@ pub fn main() {
let log_level = match flags.log_level {
Some(level) => level,
- None => Level::Warn,
+ None => Level::Info, // Default log level
};
log::set_max_level(log_level.to_level_filter());
@@ -458,13 +462,10 @@ pub fn main() {
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
DenoSubcommand::Test {
- quiet,
fail_fast,
include,
allow_none,
- } => {
- test_command(flags, include, fail_fast, quiet, allow_none).boxed_local()
- }
+ } => test_command(flags, include, fail_fast, allow_none).boxed_local(),
DenoSubcommand::Completions { buf } => {
print!("{}", std::str::from_utf8(&buf).unwrap());
return;
diff --git a/cli/permissions.rs b/cli/permissions.rs
index 9a397ea4a..6063ee9d1 100644
--- a/cli/permissions.rs
+++ b/cli/permissions.rs
@@ -4,7 +4,6 @@ use crate::flags::Flags;
use crate::op_error::OpError;
#[cfg(not(test))]
use atty;
-use log;
use std::collections::HashSet;
use std::fmt;
#[cfg(not(test))]
@@ -349,12 +348,10 @@ fn permission_prompt(_message: &str) -> bool {
}
fn log_perm_access(message: &str) {
- if log_enabled!(log::Level::Info) {
- eprintln!(
- "{}",
- colors::bold(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
- );
- }
+ debug!(
+ "{}",
+ colors::bold(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
+ );
}
fn check_path_white_list(path: &Path, white_list: &HashSet<PathBuf>) -> bool {