Skip to content

Commit

Permalink
Solve CLI parse order bug (#574)
Browse files Browse the repository at this point in the history
* solve CLI parse order bug

* add CLI test to validate fix
  • Loading branch information
arthurpaulino authored Aug 1, 2023
1 parent f36971e commit e22c786
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
36 changes: 23 additions & 13 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct LoadCli {
}

impl LoadArgs {
pub fn into_cli(self) -> LoadCli {
fn into_cli(self) -> LoadCli {
LoadCli {
lurk_file: self.lurk_file,
zstore: self.zstore,
Expand Down Expand Up @@ -175,7 +175,7 @@ struct ReplCli {
}

impl ReplArgs {
pub fn into_cli(self) -> ReplCli {
fn into_cli(self) -> ReplCli {
ReplCli {
load: self.load,
zstore: self.zstore,
Expand Down Expand Up @@ -364,17 +364,9 @@ struct VerifyArgs {
proof_id: String,
}

/// Parses CLI arguments and continues the program flow accordingly
pub fn parse_and_run() -> Result<()> {
#[cfg(not(target_arch = "wasm32"))]
paths::non_wasm::create_lurk_dirs()?;

if let Ok(repl_cli) = ReplCli::try_parse() {
repl_cli.run()
} else if let Ok(load_cli) = LoadCli::try_parse() {
load_cli.run()
} else {
match Cli::parse().command {
impl Cli {
fn run(self) -> Result<()> {
match self.command {
Command::Repl(repl_args) => repl_args.into_cli().run(),
Command::Load(load_args) => load_args.into_cli().run(),
#[allow(unused_variables)]
Expand All @@ -389,3 +381,21 @@ pub fn parse_and_run() -> Result<()> {
}
}
}

/// Parses CLI arguments and continues the program flow accordingly
pub fn parse_and_run() -> Result<()> {
#[cfg(not(target_arch = "wasm32"))]
paths::non_wasm::create_lurk_dirs()?;

if let Ok(cli) = Cli::try_parse() {
cli.run()
} else if let Ok(repl_cli) = ReplCli::try_parse() {
repl_cli.run()
} else if let Ok(load_cli) = LoadCli::try_parse() {
load_cli.run()
} else {
// force printing help
Cli::parse();
Ok(())
}
}
8 changes: 8 additions & 0 deletions tests/lurkrs-smoke-test.rs → tests/lurk-cli-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ fn test_help_command() {
cmd.arg("--help");
cmd.assert().success();
}

#[test]
fn test_repl_command() {
let mut cmd = lurk_cmd();

cmd.arg("repl");
cmd.assert().success();
}
2 changes: 1 addition & 1 deletion tests/lurk-tests.rs → tests/lurk-lib-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::Path;

#[test]
#[ignore]
fn lurk_tests() {
fn lurk_cli_tests() {
let test_files = [
"test.lurk",
"micro-tests.lurk",
Expand Down

0 comments on commit e22c786

Please sign in to comment.