Skip to content

Commit

Permalink
Add the new command to freight and update help.txt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgattozzi committed Oct 14, 2023
1 parent df674dd commit 13854bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use std::env;
use std::error::Error;
use std::fs;
use std::process;

fn main() -> Result<(), Box<dyn Error>> {
const HELP: &str = include_str!("help.txt");

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::<Vec<String>>())?,
Some("build") => freight::build()?,
Expand Down

0 comments on commit 13854bf

Please sign in to comment.