Skip to content

Commit

Permalink
Add verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and Rashad Alston committed May 26, 2022
1 parent ea60d30 commit f742e9e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
4 changes: 4 additions & 0 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
56 changes: 46 additions & 10 deletions forc/src/ops/forc_init.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +34,16 @@ fn print_welcome_message() {
);
}

pub fn canonicalize(path: &PathBuf) -> Result<String> {
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),
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f742e9e

Please sign in to comment.