Skip to content

Commit

Permalink
fix: correct --version behavior (fixes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 7, 2023
1 parent 5444b56 commit 0345282
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use clap::Parser;
use std::path::PathBuf;

#[derive(Debug, Clone, Parser)]
#[command(arg_required_else_help(true))]
pub struct Args {
#[clap(long = "lua", help = "Path to lua program to be executed")]
pub lua: PathBuf,
#[clap(help = "Path to lua program to be executed")]
pub lua: Option<PathBuf>,
#[clap(long = "version", short = 'V', help = "Print version info and exit")]
pub version: bool,
}
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ fn main() -> Result<()> {
return Ok(());
}

let program = load_file(&args.lua.to_string_lossy())?;

Ok(lua::execute(&program)?)
if let Some(lua) = &args.lua {
let program = load_file(&lua.to_string_lossy())?;
Ok(lua::execute(&program)?)
} else {
// Help will be printed out by Args.
Ok(())
}
}

/// Loads a file content as `String`.
Expand Down

0 comments on commit 0345282

Please sign in to comment.