Crates.io | trustrl |
lib.rs | trustrl |
version | 0.1.0 |
source | src |
created_at | 2023-11-27 14:31:36.499466 |
updated_at | 2023-11-27 14:31:36.499466 |
description | A URL manipulation tool |
homepage | |
repository | https://github.com/mfontanini/trustrl |
max_upload_size | |
id | 1050485 |
size | 53,175 |
URL manipulator tool.
This is a more-or-less rewrite of trurl. I liked the idea of trurl
, a tiny tool to
manipulate URLs so I rewrote it in Rust. While I was initially going to make this a one-to-one match in terms of CLI
API, I ended up making a few changes along the way. While the functionality of both tools is almost identical, their
APIs differ a bit.
Download Rust and run:
cargo build --release
The output binary is in ./target/release/trustrl
.
This tool takes either a single URL or a path to a file that contains a list of URLs. For every URL it will:
The port is {port}
, which does exactly what you'd expect.For example, rendering using a template string:
$ ./trustrl http://example.com/foo?a=b -t 'the path is {path}, the port is {port}'
the path is /foo, the port is 80
And rendering the same URL as a JSON object:
./trustrl http://example.com/foo?a=b -j | jq
{
"url": "http://example.com/foo?a=b",
"scheme": "http",
"host": "example.com",
"port": 80,
"path": "/foo",
"query": "a=b",
"params": [
{
"key": "a",
"value": "b"
}
]
}
Transformations allow changing something in each URL. For example:
$ ./trustrl example.com/foo --scheme https --port 1337 --append-path bar
https://example.com:1337/foo/bar
See the help for the full list of transformations.
The keys supported in the template string are:
query:parameter_name
/trustrl -h
Usage: trustrl [OPTIONS] <URL|--urls-path <URLS_PATH>>
Arguments:
[URL] The URL to be used
Options:
--urls-path <URLS_PATH>
A path to a list of URLs to process
-t, --template <TEMPLATE>
The template to be used to render the URL [default: {url}]
-j, --to-json
Output URLs in JSON format
-s, --scheme <SCHEME>
Set the URL's scheme
-H, --host <HOST>
Set the URL's host
-P, --port <PORT>
Set the URL's port
-p, --path <PATH>
Set the URL's path
-u, --user <USER>
Set the URL's user
-S, --password <PASSWORD>
Set the URL's password
-f, --fragment <FRAGMENT>
Set the URL's fragment
-r, --redirect <REDIRECT>
Redirect the URL to a new path
-a, --append-path <APPEND_PATH>
Append a new segment at the end of the path
-q, --append-query-string <APPEND_QUERY_STRING>
Append a new query string pair, using format `<key>[=<value>]`
-c, --clear-query-string
Clear the query string
--allow-query-string <ALLOW_QUERY_STRING>
Keep the query string keys that match this regex
--deny-query-string <DENY_QUERY_STRING>
Remove the query string keys that match this regex
--sort-query-string
Sort query string
-h, --help
Print help