Skip to content

Commit efaecb7

Browse files
committed
fix: set should error for invalid options
1 parent af0c890 commit efaecb7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/shell/commands/set.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ fn execute_set(context: &mut ShellCommandContext) -> ExecuteResult {
5454
i += 1;
5555
}
5656
} else {
57-
// Unknown argument
58-
i += 1;
57+
// unknown argument
58+
let _ = context
59+
.stderr
60+
.write_line(&format!("set: invalid option: {}", arg));
61+
return ExecuteResult::from_exit_code(1);
5962
}
6063
}
6164

tests/integration_test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,14 @@ async fn pipefail_option() {
20022002
.assert_exit_code(1)
20032003
.run()
20042004
.await;
2005+
2006+
// invalid argument
2007+
TestBuilder::new()
2008+
.command("set -x")
2009+
.assert_stderr("set: invalid option: -x\n")
2010+
.assert_exit_code(1)
2011+
.run()
2012+
.await;
20052013
}
20062014

20072015
#[tokio::test]

0 commit comments

Comments
 (0)