restish
restish copied to clipboard
Literal commas with CLI shorthand
I can't seem to find a way to include literal commas when using the CLI Shorthand Syntax. For example:
~ restish post "https://httpbin.org/post" sender.id: test, "text: Hello, CLI"
HTTP/2.0 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Length: 724
Content-Type: application/json
Date: Mon, 13 Jun 2022 18:30:07 GMT
Server: gunicorn/19.9.0
{
args: {}
data: "{\"sender\":{\"id\":\"test\"},\"text\":[\"Hello\",\"CLI\"]}"
files: {}
form: {}
headers: {
Accept: "application/cbor;q=0.9,application/msgpack;q=0.8,application/ion;q=0.6,application/json;q=0.5,application/yaml;q=0.5,text/*;q=0.2,*/*"
Accept-Encoding: "gzip, br"
Content-Length: "47"
Content-Type: "application/json; charset=utf-8"
Host: "httpbin.org"
User-Agent: "restish-0.14.0"
X-Amzn-Trace-Id: "Root=1-62a7822f-030b972753d9dc835d9eb580"
}
json: {
sender: {
id: "test"
}
text: ["Hello", "CLI"]
}
origin: "..."
url: "https://httpbin.org/post"
}
It is unexpected to me that my "Hello, CLI" becomes an array. This is what I'm trying to accomplish:
...
sender: {
id: "test"
}
text: "Hello, CLI"
}
Yes, this is one of the shortcomings of the shorthand syntax as it exists today. I'm in the process of rewriting the parser and making some changes to the language so stay tuned for some improvements, including proper escaping and quoting support.
Shorthand v2 was released, see https://github.com/danielgtaylor/shorthand/releases/tag/v2.0.0
This revamps the language and supports literal commas much better:
$ j 'foo, bar'
"foo, bar"
$ j foo\, bar
"foo, bar"