-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add quoteShellCommand #8272
add quoteShellCommand #8272
Conversation
3 (and now 4 with this PR) quoting procedures seems like going a bit overboard. Why do we have so many? |
quoteShellCommand (Nim's version of https://dlang.org/library/std/process/escape_shell_command.html) quotes command lines (ie array of arguments), whereas quoteShell (Nim's version of https://dlang.org/library/std/process/escape_shell_file_name.html) quotes only a single argument. If anything, quoteShellWindows and quoteShellPosix could be merged into the existing quoteShell, but that's a separate discussion (and there are arguments for allowing cross platform quoting, eg as a linux web service that serves windows users, etc). |
I don't know a nice way to say that, but if you want to copy everything from D, maybe you should just use D. (That said, I have nothing against this particular PR) |
So wouldn't it be better to overload
Yes, I think that should be done. That way we can just have |
I can understand this sentiment. But when using a new language it's only natural that you look for functions in the stdlib which are available in the language you are most familiar with. If these functions are simply not available then it makes sense to add them, especially if these functions are also available in other languages (which I am guessing they are). |
First, Second, this procedure should accept the "quote function" as a parameter, with But it's a one-liner. So I'm with @dom96 on this. I'd favor adding the one-liner to the docs for |
@cdunn2001 @dom96 |
The restriction of |
unfortunately this also doesn't work because openArray can't be used with import sequtils
import strutils
proc fun(a:string):auto{.cdecl.}=a
when true:
# not ok with cdecl: Error: type mismatch: got <openarray[string]...
proc test(args:openArray[string])=
echo args.map(fun).join(" ")
elif true:
# Error: invalid type: 'openarray[string]' for let
# ok cdecl but not ok with openArray
proc test(args:openArray[string])=
echo args.mapIt(fun(it)).join(" ")
else:
# ok with cdecl but won't accept same stuff as openArray
proc test(args:seq[string])=
echo args.mapIt(fun(it)).join(" ")
let args = @["foo"]
test(args)
|
@timotheecour Tests have failed. |
3e1d7ca
to
4766c37
Compare
4766c37
to
3fc96bb
Compare
PTAL : tests are green now that I fixed #8577 |
Why do we need it? It's confusing. Don't add it. Your explanation was in D-specific terms that I can't follow. |
the exact same functionality exists in D, C#, perl, node, ruby, go, and probably much more (I added links to all these functions in top-level message). It's used for example to safely escape an array of arguments to a function accepting a string, eg even though some procs in osproc.nim accept an array of arguments, they're not easily interchangeable and in some cases using a string is more convenient (maybe the string will be constructed partially from an existing shell quoted string, and appended to |
Ok, then write it without the |
e00ceaa
to
c9d42c1
Compare
done, used a for-loop; indeed a temp sequence would be created via PTAL |
Can we remove/merge the other quoting procs while we're at it? |
No, these are rather well designed. |
same as: