Skip to content
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

Get path components by index / json array #291

Open
elig0n opened this issue May 6, 2024 · 8 comments · May be fixed by #311
Open

Get path components by index / json array #291

elig0n opened this issue May 6, 2024 · 8 comments · May be fixed by #311

Comments

@elig0n
Copy link

elig0n commented May 6, 2024

Where something like: trurl -g {path:2} would get the 2nd slash separated element of a URL path.

The slash separated elements can also take a form of array in the JSON output. Making it easier for parsing.

@bagder
Copy link
Member

bagder commented May 6, 2024

I presume that would make the JSON output perhaps look like something like this?

$ trurl --json curl.se/1/2/3
[
  {
    "url": "http://curl.se/one/two/three",
    "parts": {
      "scheme": "http",
      "host": "curl.se",
      "path": "/one/two/three"
    },
    "path": [
       "one",
       "two",
       "three"  
    ]
  }
]

@elig0n
Copy link
Author

elig0n commented May 6, 2024

@bagder Sure why not? I'll leave the implementation specifics up to the developers.

This can also apply to the "host" part i.e. have it split into: domain, subdomain, tld

@bagder
Copy link
Member

bagder commented May 6, 2024

This can also apply to the "host" part i.e. have it split into: domain, subdomain, tld

I suppose that would then be a "host" array since it can in theory contain a large number of parts. A reverse-sorted list perhaps so that it starts with the TLD?

(I just want to be clear that I'm not entirely convinced trurl needs these features, but I'm testing out the ideas and how they would work as a process to making up my mind.)

@dfandrich
Copy link
Contributor

dfandrich commented May 7, 2024 via email

@elig0n
Copy link
Author

elig0n commented May 7, 2024

I suppose that would then be a "host" array since it can in theory contain a large number of parts. A reverse-sorted list perhaps so that it starts with the TLD?

Maybe just another sub-object with key-value pairs would suffice

@bagder
Copy link
Member

bagder commented May 13, 2024

Since a path is always separated by slashes and a host name is always separated by periods, I don't quite see the need for trurl to that that splitting. There are plenty of help in tools and languages to split a string by a given separator.

As @dfandrich mentions, getting a PSL out of the host name would be different - but that would require either a API change in libcurl or that trurl accesses libpsl itself. Not something I personally feel is worth it.

@elig0n
Copy link
Author

elig0n commented May 13, 2024

Why would you defer the job of splitting paths in the JSON trurl generates to the user who runs i.e. jq ? They should only care about extracting the data they need and not parsing. A common Unix philosophy says: do one thing and do it well.

@emanuele6
Copy link
Collaborator

emanuele6 commented May 13, 2024

A common Unix philosophy says: do one thing and do it well.

The entire point of that is to not do overly task-specific things in your tools so that the tool can be more generic and it is possible to use external tools to easily integrate it in many different complex applications.
I don't understand how else you are interpreting that saying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants