diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 19dc5ce4b0..e80bf3a61e 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -6006,5 +6006,15 @@ mod tests { ..Flags::default() } ); + + let r = flags_from_vec(svec!["deno", "init", "--quiet"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Init(InitFlags { dir: None }), + log_level: Some(Level::Error), + ..Flags::default() + } + ); } } diff --git a/cli/tests/integration/init_tests.rs b/cli/tests/integration/init_tests.rs index a7a54f06bf..e597e117c0 100644 --- a/cli/tests/integration/init_tests.rs +++ b/cli/tests/integration/init_tests.rs @@ -15,17 +15,17 @@ fn init_subcommand_without_dir() { let output = deno_cmd .current_dir(cwd) .arg("init") - .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() .unwrap(); assert!(output.status.success()); - let stdout = String::from_utf8(output.stdout).unwrap(); - assert_contains!(stdout, "Project initialized"); - assert!(!stdout.contains("cd")); - assert_contains!(stdout, "deno run main.ts"); - assert_contains!(stdout, "deno test"); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert_contains!(stderr, "Project initialized"); + assert!(!stderr.contains("cd")); + assert_contains!(stderr, "deno run main.ts"); + assert_contains!(stderr, "deno test"); let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir); let output = deno_cmd @@ -67,17 +67,17 @@ fn init_subcommand_with_dir_arg() { .current_dir(cwd) .arg("init") .arg("my_dir") - .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() .unwrap(); assert!(output.status.success()); - let stdout = String::from_utf8(output.stdout).unwrap(); - assert_contains!(stdout, "Project initialized"); - assert_contains!(stdout, "cd my_dir"); - assert_contains!(stdout, "deno run main.ts"); - assert_contains!(stdout, "deno test"); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert_contains!(stderr, "Project initialized"); + assert_contains!(stderr, "cd my_dir"); + assert_contains!(stderr, "deno run main.ts"); + assert_contains!(stderr, "deno test"); let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir); let output = deno_cmd @@ -108,3 +108,52 @@ fn init_subcommand_with_dir_arg() { let stdout = String::from_utf8(output.stdout).unwrap(); assert_contains!(stdout, "1 passed"); } + +#[test] +fn init_subcommand_with_quiet_arg() { + let temp_dir = TempDir::new(); + let cwd = temp_dir.path(); + let deno_dir = util::new_deno_dir(); + + let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir); + let output = deno_cmd + .current_dir(cwd) + .arg("init") + .arg("--quiet") + .stdout(Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let stdout = String::from_utf8(output.stdout).unwrap(); + assert_eq!(stdout, ""); + + let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir); + let output = deno_cmd + .current_dir(cwd) + .env("NO_COLOR", "1") + .arg("run") + .arg("main.ts") + .stdout(Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + assert_eq!(output.stdout, b"Add 2 + 3 = 5\n"); + + let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir); + let output = deno_cmd + .current_dir(cwd) + .env("NO_COLOR", "1") + .arg("test") + .stdout(Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let stdout = String::from_utf8(output.stdout).unwrap(); + assert_contains!(stdout, "1 passed"); +} diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index 0966a99276..4911ca7dd7 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -4,6 +4,7 @@ use crate::args::InitFlags; use crate::deno_std; use deno_core::anyhow::Context; use deno_core::error::AnyError; +use log::info; use std::io::Write; use std::path::Path; @@ -39,12 +40,12 @@ pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { .replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL.as_str()); create_file(&dir, "main_test.ts", &main_test_ts)?; - println!("✅ Project initialized"); - println!("Run these commands to get started"); + info!("✅ Project initialized"); + info!("Run these commands to get started"); if let Some(dir) = init_flags.dir { - println!(" cd {}", dir); + info!(" cd {}", dir); } - println!(" deno run main.ts"); - println!(" deno test"); + info!(" deno run main.ts"); + info!(" deno test"); Ok(()) }