Skip to content

Commit

Permalink
Add basic arg parsing for Freight
Browse files Browse the repository at this point in the history
This does basic argument parsing for freight so that we can make freight
more useful by adding commands to actually run the program with and do
things with them. Following adding the command for printing out a help
message, we will add the build command so that we can well build freight
and other projects. Once we do we'll be able to remove the stage1 cfg
flags because we'll have a generic strategy for building things. The
only difference will be where it outputs it's build files which the
Justfile will take care of.
  • Loading branch information
mgattozzi committed Jul 22, 2023
1 parent 5162ada commit 45fe054
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion justfile
@@ -1,6 +1,6 @@
run: build
./target/bootstrap_stage0/freight_stage0
./target/bootstrap_stage1/freight_stage1
./target/bootstrap_stage1/freight_stage1 help
build:
mkdir -p target/bootstrap_stage0
# Build crate dependencies
Expand Down
21 changes: 20 additions & 1 deletion src/main.rs
Expand Up @@ -37,7 +37,26 @@ fn main() -> Result<(), Box<dyn Error>> {
}
#[cfg(stage1)]
{
println!("Bootstrapped successfully!");
use std::env;
use std::process;

const HELP: &str = "\
Alternative for Cargo\n\n\
Usage: freight [COMMAND] [OPTIONS]\n\n\
Commands:\n \
help Print out this message
";

let mut args = env::args().skip(1);
match args.next().as_ref().map(String::as_str) {
Some("help") => println!("{HELP}"),
_ => {
println!("Unsupported command");
println!("{HELP}");

process::exit(1);
}
}
}

Ok(())
Expand Down

0 comments on commit 45fe054

Please sign in to comment.