mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 02:22:40 +00:00
Add global "quiet" flag (#4135)
This commit is contained in:
parent
dca00211ab
commit
62f4a2a788
5 changed files with 48 additions and 29 deletions
|
@ -22,6 +22,7 @@ use deno_core::Buf;
|
||||||
use deno_core::ErrBox;
|
use deno_core::ErrBox;
|
||||||
use deno_core::ModuleSpecifier;
|
use deno_core::ModuleSpecifier;
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
|
use log::info;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -373,11 +374,12 @@ impl TsCompiler {
|
||||||
|
|
||||||
let ts_compiler = self.clone();
|
let ts_compiler = self.clone();
|
||||||
|
|
||||||
eprintln!(
|
info!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
colors::green("Compile".to_string()),
|
colors::green("Compile".to_string()),
|
||||||
module_url.to_string()
|
module_url.to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let msg = execute_in_thread(global_state.clone(), req_msg).await?;
|
let msg = execute_in_thread(global_state.clone(), req_msg).await?;
|
||||||
|
|
||||||
let json_str = std::str::from_utf8(&msg).unwrap();
|
let json_str = std::str::from_utf8(&msg).unwrap();
|
||||||
|
|
|
@ -9,9 +9,9 @@ use crate::op_error::OpError;
|
||||||
use deno_core::ErrBox;
|
use deno_core::ErrBox;
|
||||||
use deno_core::ModuleSpecifier;
|
use deno_core::ModuleSpecifier;
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
|
use log::info;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use std;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
@ -23,7 +23,6 @@ use std::result::Result;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use url;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// Structure representing local or remote file.
|
/// Structure representing local or remote file.
|
||||||
|
@ -414,11 +413,12 @@ impl SourceFileFetcher {
|
||||||
.boxed_local();
|
.boxed_local();
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!(
|
info!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
colors::green("Download".to_string()),
|
colors::green("Download".to_string()),
|
||||||
module_url.to_string()
|
module_url.to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
let dir = self.clone();
|
let dir = self.clone();
|
||||||
let module_url = module_url.clone();
|
let module_url = module_url.clone();
|
||||||
let module_etag = match self.http_cache.get(&module_url) {
|
let module_etag = match self.http_cache.get(&module_url) {
|
||||||
|
|
41
cli/flags.rs
41
cli/flags.rs
|
@ -59,7 +59,6 @@ pub enum DenoSubcommand {
|
||||||
},
|
},
|
||||||
Test {
|
Test {
|
||||||
fail_fast: bool,
|
fail_fast: bool,
|
||||||
quiet: bool,
|
|
||||||
allow_none: bool,
|
allow_none: bool,
|
||||||
include: Option<Vec<String>>,
|
include: Option<Vec<String>>,
|
||||||
},
|
},
|
||||||
|
@ -231,6 +230,9 @@ pub fn flags_from_vec_safe(args: Vec<String>) -> clap::Result<Flags> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if matches.is_present("quiet") {
|
||||||
|
flags.log_level = Some(Level::Error);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(m) = matches.subcommand_matches("run") {
|
if let Some(m) = matches.subcommand_matches("run") {
|
||||||
run_parse(&mut flags, m);
|
run_parse(&mut flags, m);
|
||||||
|
@ -283,6 +285,18 @@ fn clap_root<'a, 'b>() -> App<'a, 'b> {
|
||||||
.possible_values(&["debug", "info"])
|
.possible_values(&["debug", "info"])
|
||||||
.global(true),
|
.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(bundle_subcommand())
|
||||||
.subcommand(completions_subcommand())
|
.subcommand(completions_subcommand())
|
||||||
.subcommand(eval_subcommand())
|
.subcommand(eval_subcommand())
|
||||||
|
@ -505,7 +519,6 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
|
|
||||||
run_test_args_parse(flags, matches);
|
run_test_args_parse(flags, matches);
|
||||||
|
|
||||||
let quiet = matches.is_present("quiet");
|
|
||||||
let failfast = matches.is_present("failfast");
|
let failfast = matches.is_present("failfast");
|
||||||
let allow_none = matches.is_present("allow_none");
|
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 {
|
flags.subcommand = DenoSubcommand::Test {
|
||||||
quiet,
|
|
||||||
fail_fast: failfast,
|
fail_fast: failfast,
|
||||||
include,
|
include,
|
||||||
allow_none,
|
allow_none,
|
||||||
|
@ -866,13 +878,6 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
.help("Stop on first error")
|
.help("Stop on first error")
|
||||||
.takes_value(false),
|
.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(
|
||||||
Arg::with_name("allow_none")
|
Arg::with_name("allow_none")
|
||||||
.long("allow-none")
|
.long("allow-none")
|
||||||
|
@ -1947,6 +1952,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]
|
#[test]
|
||||||
fn completions() {
|
fn completions() {
|
||||||
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]).unwrap();
|
let r = flags_from_vec_safe(svec!["deno", "completions", "bash"]).unwrap();
|
||||||
|
@ -2109,7 +2129,6 @@ mod tests {
|
||||||
Flags {
|
Flags {
|
||||||
subcommand: DenoSubcommand::Test {
|
subcommand: DenoSubcommand::Test {
|
||||||
fail_fast: false,
|
fail_fast: false,
|
||||||
quiet: false,
|
|
||||||
allow_none: true,
|
allow_none: true,
|
||||||
include: Some(svec!["dir1/", "dir2/"]),
|
include: Some(svec!["dir1/", "dir2/"]),
|
||||||
},
|
},
|
||||||
|
|
15
cli/lib.rs
15
cli/lib.rs
|
@ -81,6 +81,7 @@ use url::Url;
|
||||||
|
|
||||||
static LOGGER: Logger = Logger;
|
static LOGGER: Logger = Logger;
|
||||||
|
|
||||||
|
// TODO(ry) Switch to env_logger or other standard crate.
|
||||||
struct Logger;
|
struct Logger;
|
||||||
|
|
||||||
impl log::Log for Logger {
|
impl log::Log for Logger {
|
||||||
|
@ -97,7 +98,11 @@ impl log::Log for Logger {
|
||||||
target.push_str(&line_no.to_string());
|
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) {}
|
fn flush(&self) {}
|
||||||
|
@ -372,7 +377,6 @@ async fn test_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
include: Option<Vec<String>>,
|
include: Option<Vec<String>>,
|
||||||
fail_fast: bool,
|
fail_fast: bool,
|
||||||
_quiet: bool,
|
|
||||||
allow_none: bool,
|
allow_none: bool,
|
||||||
) -> Result<(), ErrBox> {
|
) -> Result<(), ErrBox> {
|
||||||
let global_state = GlobalState::new(flags.clone())?;
|
let global_state = GlobalState::new(flags.clone())?;
|
||||||
|
@ -427,7 +431,7 @@ pub fn main() {
|
||||||
|
|
||||||
let log_level = match flags.log_level {
|
let log_level = match flags.log_level {
|
||||||
Some(level) => level,
|
Some(level) => level,
|
||||||
None => Level::Warn,
|
None => Level::Info, // Default log level
|
||||||
};
|
};
|
||||||
log::set_max_level(log_level.to_level_filter());
|
log::set_max_level(log_level.to_level_filter());
|
||||||
|
|
||||||
|
@ -458,13 +462,10 @@ pub fn main() {
|
||||||
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
|
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
|
||||||
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
||||||
DenoSubcommand::Test {
|
DenoSubcommand::Test {
|
||||||
quiet,
|
|
||||||
fail_fast,
|
fail_fast,
|
||||||
include,
|
include,
|
||||||
allow_none,
|
allow_none,
|
||||||
} => {
|
} => test_command(flags, include, fail_fast, allow_none).boxed_local(),
|
||||||
test_command(flags, include, fail_fast, quiet, allow_none).boxed_local()
|
|
||||||
}
|
|
||||||
DenoSubcommand::Completions { buf } => {
|
DenoSubcommand::Completions { buf } => {
|
||||||
print!("{}", std::str::from_utf8(&buf).unwrap());
|
print!("{}", std::str::from_utf8(&buf).unwrap());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::flags::Flags;
|
||||||
use crate::op_error::OpError;
|
use crate::op_error::OpError;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use atty;
|
use atty;
|
||||||
use log;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
@ -349,12 +348,10 @@ fn permission_prompt(_message: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_perm_access(message: &str) {
|
fn log_perm_access(message: &str) {
|
||||||
if log_enabled!(log::Level::Info) {
|
debug!(
|
||||||
eprintln!(
|
"{}",
|
||||||
"{}",
|
colors::bold(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
|
||||||
colors::bold(format!("{}️ Granted {}", PERMISSION_EMOJI, message))
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_path_white_list(path: &Path, white_list: &HashSet<PathBuf>) -> bool {
|
fn check_path_white_list(path: &Path, white_list: &HashSet<PathBuf>) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue