Skip to content

Commit

Permalink
feat: simplified command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoury committed Jul 4, 2024
1 parent a5311f2 commit e3bd01f
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
use clap::{Parser, Subcommand};
use clap::Parser;
use husk::{execute_script, repl};

#[derive(Parser, Debug)]
struct Cli {
#[clap(subcommand)]
command: Command,
}

#[derive(Subcommand, Debug)]
enum Command {
/// Executes a husk script
Run { file: std::path::PathBuf },

/// Runs the husk REPL
Repl,
/// Run a Husk script
file: Option<std::path::PathBuf>,
}

fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

match cli {
Cli {
command: Command::Run { file },
} => {
let code = std::fs::read_to_string(file)?;
match execute_script(&code) {
Ok(_) => {}
Err(e) => {
eprintln!("{}", e.pretty_print(code));
std::process::exit(1);
}
if let Some(file) = cli.file {
let code = std::fs::read_to_string(file)?;
match execute_script(&code) {
Ok(_) => {}
Err(e) => {
eprintln!("{}", e.pretty_print(code));
std::process::exit(1);
}
}
Cli {
command: Command::Repl,
} => {
let _ = repl();
}
} else {
let _ = repl();
}

Ok(())
Expand Down

0 comments on commit e3bd01f

Please sign in to comment.