From 43b00fa43ebe883f913cf492187c6800ac3d1ccd Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 2 Jan 2022 08:37:14 +0000 Subject: [PATCH 1/2] Doc: nitpick `--` has no special meaning to shells The shell (e.g. bash) does not interpret your `argv` - deciding which arguments to interpret as flags or whether your program even supports flags is entirely up to you. --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 52c2c3a..b945ec0 100644 --- a/README.md +++ b/README.md @@ -218,13 +218,19 @@ done ``` ### Edge cases -replace/-with string needs extra `--` before it, if starts with double-minus -(this is a limitation of the bash itself) +sd will interpret every argument starting with `--` as a (potentially unknown) flag. +The common convention of using `--` to signal the end of flags is respected: ```bash -echo "test/test" | sd '/' -- '--inteneded--' -test--inteneded--test +$ echo "./hello foo" | sd "foo" "--world" +error: Found argument '--world' which wasn't expected, or isn't valid in this context -echo "start/--/end" | sd --string-mode -- '--' 'middle' -start/middle/end +USAGE: + sd [OPTIONS] [files]... + +For more information try --help +$ echo "./hello foo" | sd "foo" -- "--world" +./hello --world +$ echo "./hello --foo" | sd -- "--foo" "--world" +./hello --world ``` From 654e23bbd6b45b0e20bf06fe5950c85394cec7a4 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 2 Jan 2022 09:00:29 +0000 Subject: [PATCH 2/2] Nitpick: a flag can start with `-` too --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b945ec0..13ea0f2 100644 --- a/README.md +++ b/README.md @@ -218,19 +218,19 @@ done ``` ### Edge cases -sd will interpret every argument starting with `--` as a (potentially unknown) flag. +sd will interpret every argument starting with `-` as a (potentially unknown) flag. The common convention of using `--` to signal the end of flags is respected: ```bash -$ echo "./hello foo" | sd "foo" "--world" -error: Found argument '--world' which wasn't expected, or isn't valid in this context +$ echo "./hello foo" | sd "foo" "-w" +error: Found argument '-w' which wasn't expected, or isn't valid in this context USAGE: sd [OPTIONS] [files]... For more information try --help -$ echo "./hello foo" | sd "foo" -- "--world" -./hello --world -$ echo "./hello --foo" | sd -- "--foo" "--world" -./hello --world +$ echo "./hello foo" | sd "foo" -- "-w" +./hello -w +$ echo "./hello --foo" | sd -- "--foo" "-w" +./hello -w ```