-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Posix compliant argument parsing for
-c
mode (#147)
clap does not handle `--` as an argument but rather as a separator so we need additional processing for passing `--` as an operand to a `-c` script. This is because Posix interprets `--` as an operand. The first argument in `-c` is the name of the command and can be `--` just fine. - Added functions `try_parse_known` and `parse_known` for splitting arguments into `before hyphen` and `hyphen and after hyphen` - This approach allows manually deciding what to do with `--` and the remaining arguments
- Loading branch information
Showing
6 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: "Argument handling tests" | ||
common_test_files: | ||
- path: "script.sh" | ||
contents: | | ||
echo \"$0\" \"$1\" \"$2\" \"$@\" | ||
cases: | ||
- name: "-c mode arguments without --" | ||
args: | ||
- "-c" | ||
- 'echo \"$0\" \"$1\" \"$2\" \"$@\"' | ||
- 1 | ||
- "-2" | ||
- "3" | ||
|
||
- name: "-c mode arguments with --" | ||
args: | ||
- "-c" | ||
- 'echo \"$0\" \"$1\" \"$2\" \"$@\"' | ||
- "--" | ||
- 1 | ||
- 2 | ||
- 3 | ||
|
||
- name: "-c mode and arguments with +O" | ||
args: | ||
- "+O" | ||
- "nullglob" | ||
- "-c" | ||
- 'echo \"$0\" \"$1\" \"$2\" \"$@\"' | ||
- "--" | ||
- 1 | ||
- 2 | ||
- 3 | ||
|
||
- name: "-c mode -- torture" | ||
args: | ||
- "-c" | ||
- 'echo \"$0\" \"$1\" \"$2\" \"$@\"' | ||
- -- | ||
- -- | ||
- -&-1 | ||
- --! | ||
- "\"-2\"" | ||
- "''--''" | ||
- 3--* | ||
|
||
- name: "-c modeonly one --" | ||
args: | ||
- "-c" | ||
- 'echo \"$0\" \"$1\" \"$2\" \"$@\"' | ||
- -- | ||
|
||
- name: "script arguments without --" | ||
args: | ||
- script.sh | ||
- -1 | ||
- -2 | ||
- -3 | ||
|
||
- name: "script arguments with --" | ||
args: | ||
- script.sh | ||
- -- | ||
- --1 | ||
- -2 | ||
- 3 | ||
|
||
- name: "script -- torture" | ||
args: | ||
- script.sh | ||
- -- | ||
- "--" | ||
- -- | ||
- -!-1* | ||
- "\"-2\"" | ||
- -- | ||
- 3-- | ||
|
||
- name: "script only one --" | ||
args: | ||
- script.sh | ||
- -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: "Builtins: echo" | ||
cases: | ||
- name: "echo with only --" | ||
stdin: echo -- | ||
|
||
- name: "echo with -- and args" | ||
stdin: echo -- -1 --"aaa" ?^1as- |