Skip to content

Commit

Permalink
fix: exit error code on arg parse failure (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Mar 21, 2024
1 parent 7d0e506 commit e8f8954
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/shell/commands/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ impl ShellCommand for ExitCommand {
let result = match execute_exit(context.args) {
Ok(code) => ExecuteResult::Exit(code, Vec::new()),
Err(err) => {
// even if parsing args fails `exit` always exits
context.stderr.write_line(&format!("exit: {err}")).unwrap();
ExecuteResult::Exit(1, Vec::new())
ExecuteResult::Exit(2, Vec::new())
}
};
Box::pin(futures::future::ready(result))
Expand Down
7 changes: 7 additions & 0 deletions src/shell/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ async fn exit() {
.assert_exit_code(1)
.run()
.await;

TestBuilder::new()
.command("exit bad args")
.assert_stderr("exit: too many arguments\n")
.assert_exit_code(2)
.run()
.await;
}

#[tokio::test]
Expand Down

0 comments on commit e8f8954

Please sign in to comment.