From f742e9e70b08df00de3574adb7d8cc52c77da0c0 Mon Sep 17 00:00:00 2001 From: Rashad Alston Date: Thu, 26 May 2022 08:54:33 -0700 Subject: [PATCH] Add verbosity --- forc-util/src/lib.rs | 4 +++ forc/src/ops/forc_init.rs | 56 ++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/forc-util/src/lib.rs b/forc-util/src/lib.rs index b9dc06698c6..0558cc02810 100644 --- a/forc-util/src/lib.rs +++ b/forc-util/src/lib.rs @@ -207,6 +207,10 @@ pub fn println_green(txt: &str) { println_std_out(txt, TermColor::Green); } +pub fn println_light_blue(txt: &str) { + println_std_out(txt, TermColor::Rgb(40, 200, 255)); +} + pub fn print_light_blue(txt: &str) { let stdout = StandardStream::stdout(ColorChoice::Always); print_with_color(txt, TermColor::Rgb(40, 200, 255), stdout); diff --git a/forc/src/ops/forc_init.rs b/forc/src/ops/forc_init.rs index 4f466eece3f..2532e5d27f8 100644 --- a/forc/src/ops/forc_init.rs +++ b/forc/src/ops/forc_init.rs @@ -1,7 +1,7 @@ use crate::cli::InitCommand; use crate::utils::{defaults, program_type::ProgramType::*}; use anyhow::Result; -use forc_util::{println_green, validate_name}; +use forc_util::{println_green, println_light_blue, validate_name}; use std::fs; use std::path::{Path, PathBuf}; use sway_utils::constants; @@ -34,6 +34,16 @@ fn print_welcome_message() { ); } +pub fn canonicalize(path: &PathBuf) -> Result { + match std::fs::canonicalize(path) { + Ok(p) => { + let as_str = String::from(p.to_string_lossy()); + Ok(as_str) + } + Err(e) => anyhow::bail!("Could not derive canonical path: '{}'", e), + } +} + pub fn init(command: InitCommand) -> Result<()> { let project_dir = match &command.path { Some(p) => PathBuf::from(p), @@ -63,6 +73,16 @@ pub fn init(command: InitCommand) -> Result<()> { // Make a new directory for the project fs::create_dir_all(Path::new(&project_dir).join("src"))?; + if command.verbose { + println_light_blue(&format!( + "\nUsing project directory at {}", + canonicalize(&project_dir)? + )) + } + + // Make directory for tests + fs::create_dir_all(Path::new(&project_dir).join("tests"))?; + // Insert default manifest file match program_type { Library => fs::write( @@ -75,6 +95,12 @@ pub fn init(command: InitCommand) -> Result<()> { )?, } + // Insert default test manifest file + fs::write( + Path::new(&project_dir).join(constants::TEST_MANIFEST_FILE_NAME), + defaults::default_tests_manifest(project_name), + )?; + match program_type { Contract => fs::write( Path::new(&project_dir) @@ -103,19 +129,29 @@ pub fn init(command: InitCommand) -> Result<()> { } // Insert default test function - fs::write( - Path::new(&project_name).join("tests").join("harness.rs"), - defaults::default_test_program(project_name), - )?; + let harness_path = Path::new(&project_dir).join("tests").join("harness.rs"); + fs::write(&harness_path, defaults::default_test_program(project_name))?; + + if command.verbose { + println_light_blue(&format!( + "\nCreating test harness at {}", + canonicalize(&harness_path)? + )); + } // Ignore default `out` and `target` directories created by forc and cargo. - fs::write( - Path::new(&project_name).join(".gitignore"), - defaults::default_gitignore(), - )?; + let gitignore_path = Path::new(&project_dir).join(".gitignore"); + fs::write(&gitignore_path, defaults::default_gitignore())?; + + if command.verbose { + println_light_blue(&format!( + "\nCreating .gitignore at {}", + canonicalize(&gitignore_path)? + )); + } println_green(&format!( - "Successfully created {program_type}: {project_name}", + "\nSuccessfully created {program_type}: {project_name}", )); print_welcome_message();