Replies: 2 comments 2 replies
-
This all looks good, I think you point out a lot of operations that don't have good ergonomics so they require some strange tricks within a calling script. I think splitting the JSON stuff across multiple objects makes sense and would allow for easier-to-read JSON (as well as making scripting easier). The only part I'm a bit confused about is:
Can you provide an example output of what these would be like? |
Beta Was this translation helpful? Give feedback.
-
(You should probably have submitted these as separate ideas to better facilitate discussions on each separate idea)
Let's get rid of that. It was never a good idea and basically just happened because the set code uses the same list of components.
Very sensible reasoning. The existing output format was just organically created and mostly by me, and I do not have a lot of experience with working with JSON data in scripts etc so likely to do newbie mistakes like this.
I think I'm with you on this one as well. It seems to lead to better consistency and that's something I like. |
Beta Was this translation helpful? Give feedback.
-
Remove
-s 'url=...'
It is just an alternate version of
--redirect ...
that does not respect--accept-space
and--no-guess-url
, I propose removing it.Rework
--json
outputIt is a bit annoying to work with
--json
now that there are meta properties likeparams
,raw_port
, and others that may be added in the future at the same level of the components.E.g. if, in
jq
, I want to check if two URLs are semantically equivalent except for one component (e.g. host), I have to do something like:Or:
I think
--json
would be much more usable and easier to handle if the parts were in a separate object like so (note,"url"
is NOT a part):I mostly want to use
trurl --json
to extract URL parts, and get the normalised URL in "url".If it was structured that way, I could just use:
If I wanted to filter out URLs that are not http:// or https:// and remove URLs that are equivalent ignoring the scheme, and keep https:// over http:// (#200 (comment)), I can use:
And, if I wanted to write a jq script that modifies one of the parts, and outputs a shell command that runs trurl with some
--set
options, and outputs the modified URL, I could simply iterate the parts object without listing all the properties, checking if the key is present, etc:Or to process URLs as they come in a pipeline:
URL in default output, and --get and --json
When using trurl, I often want it to behave as if I passed
-g '{url}'
or-g '{puny:url}'
so i get the default port for known schemes printed, and punyfied host names.But, if I use
--json
, I can't access the punyfied version of the URL or the URL with explicit default port.Not an extremely big deal, at least in a shell script that uses jq, since I can just pipe the URLs outputted by jq into another trurl process like so, but it would surely be annoying in other languages:
Also, there is no way to get the punyfied URL without the default port. Except using hacks like this one:
And there is no way to get the URL without default port at all in
-g
.I propose to add two new options, one that makes the default output print the hostname in punycode (--punycode), and one that makes the default output include default ports
--default-port
. You may specify both of them to make trurl output punyfied URLs with explict default ports.The "url" field in
--json
will reflect the default output.Remove
{raw:}
, and replace it with{default:}
.{puny:}
and{default:}
may be specified for any component in any order (e.g.,{puny:default:host}
,{default:puny:query}
,{:puny:default:url}
) as generic modfiers like{:component}
, naturally they will not change anything for some components.{url}
expands to the default output, unless any modifier is specified. In which case,curl_url_get()
will be called with the bitwise of:CURLU_PUNYCODE
if{puny:
is specified,CURLU_URLENCODE
if{:
is specified,CURLU_DEFAULT_PORT
if{default:
is specified.This will incidentally also fix the behaviour of
{raw:port}
that is currently different from theraw_port
present in the--json
output.{raw:port}
and{port}
currently maketrurl
callcurl_get_url()
with a combination of flags that yields the following results:vs
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions