From 13854bfed1d1a76e5bac8123264b3edfb502d032 Mon Sep 17 00:00:00 2001 From: Michael Gattozzi Date: Sat, 14 Oct 2023 20:50:49 +0000 Subject: [PATCH] Add the new command to freight and update help.txt This adds the command `new` to freight which creates a brand new project in a given directory. It is exactly like init, but you choose where to initialize the project. We also update the help text to include both the init command which had not been updated in the help text and the new command. --- src/help.txt | 2 ++ src/main.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/help.txt b/src/help.txt index 4c22ab9..05303b5 100644 --- a/src/help.txt +++ b/src/help.txt @@ -3,6 +3,8 @@ Alternative for Cargo Usage: freight [COMMAND] [OPTIONS] Commands: + new Create a new Freight Project with a given path + init Create a new Freight Project in the current directory run Build and run a Freight or Cargo Project build Build a Freight or Cargo project test Test a Freight or Cargo project diff --git a/src/main.rs b/src/main.rs index be9c23c..dd6af30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::env; use std::error::Error; +use std::fs; use std::process; fn main() -> Result<(), Box> { @@ -7,6 +8,15 @@ fn main() -> Result<(), Box> { let mut args = env::args().skip(1); match args.next().as_ref().map(String::as_str) { + Some("new") => { + if let Some(dir) = &args.next() { + fs::create_dir_all(&dir)?; + freight::init(&dir)?; + } else { + println!("No directory given"); + process::exit(1); + } + } Some("init") => freight::init(&env::current_dir()?)?, Some("run") => freight::run(args.collect::>())?, Some("build") => freight::build()?,