ericcornelissen/shescape

Support escaping flags & options

Closed this issue · 1 comments

Feature Request

Description

Add support for escaping inputs that may be interpreted as flags/options (for Unix, arguments starting with - or -- appearing before an argument that is exactly --). This may be necessary as using a flag can change the behavior of a command unintentionally - for example, consider being able to add the --force flag to certain commands.

Proposal

To be decided (suggestions welcome)

Since flags/options are a convention rather than a shell requirement it will be hard to properly support this. On Unix systems flags/options nearly always start with - or --1 (I think this is a POSIX standard). On Windows systems / is used historically (from DOS), but many CLI tools accept - or -- nowadays. Thus, it seems the best approach is to "escape" leading - on Unix systems and leading / and - on Windows systems and allow users of Shescape to change the set of flag/option characters in case their tool does something else.

From my testing (and based on my understanding) "escaping" these characters (e.g. - as \- for Bash) won't work because the CLI program will receive the escaped characters (in this case just -). So, to "escape" flags/options, leading - (and / for Windows) will have to be removed entirely.

For the purposes of v1, this should be opt-in behavior since this really seems like a breaking change. In v2 the default behavior should be to "escape" flags/options, with an option to opt-out.

Footnotes

  1. Interestingly a string like ' --xyz' (flag with leading space that's preserved due to quoting) is rejected by all CLI tools I tested. But this is strictly an implementation detail, so even such strings should be "escaped".