2020-02-03 00:05:18 +01:00
# url-parser
2023-08-22 09:46:00 +02:00
Simple command-line URL parser
2023-08-21 16:06:34 +02:00
[![Build Status ](https://ci.thegeeklab.de/api/badges/thegeeklab/url-parser/status.svg )](https://ci.thegeeklab.de/repos/thegeeklab/url-parser)
2020-09-21 20:24:51 +02:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/thegeeklab/url-parser )](https://goreportcard.com/report/github.com/thegeeklab/url-parser)
2020-09-21 20:54:34 +02:00
[![GitHub contributors ](https://img.shields.io/github/contributors/thegeeklab/url-parser )](https://github.com/thegeeklab/url-parser/graphs/contributors)
2021-01-04 16:49:49 +01:00
[![License: MIT ](https://img.shields.io/github/license/thegeeklab/url-parser )](https://github.com/thegeeklab/url-parser/blob/main/LICENSE)
2020-02-03 00:05:18 +01:00
Inspired by [herloct/url-parser ](https://github.com/herloct/url-parser ), a simple command-line utility for parsing URLs.
2021-10-25 12:48:09 +02:00
## Installation
2020-02-03 00:05:18 +01:00
2023-08-21 16:06:34 +02:00
Prebuilt multiarch binaries are available for Linux only.
2020-02-03 00:05:18 +01:00
```Shell
2023-10-17 14:38:17 +02:00
curl -SsfL https://github.com/thegeeklab/url-parser/releases/latest/download/url-parser-linux-amd64 -o /usr/local/bin/url-parser
2020-02-03 00:05:18 +01:00
chmod +x /usr/local/bin/url-parser
```
2021-10-25 12:48:09 +02:00
## Build
Build the binary from source with the following command:
```Shell
2022-04-25 12:56:32 +02:00
make build
2021-10-25 12:48:09 +02:00
```
2020-02-03 00:05:18 +01:00
## Usage
```Shell
$ url-parser --help
NAME:
url-parser - Parse URL and shows the part of it.
USAGE:
url-parser [global options] command [command options] [arguments...]
VERSION:
2020-02-03 15:00:54 +01:00
devel
2020-02-03 00:05:18 +01:00
COMMANDS:
2020-02-03 15:00:54 +01:00
all, a Get all parts from url
scheme, s Get scheme from url
user, u Get username from url
password, pw Get password from url
path, pt Get path from url
host, h Get hostname from url
port, p Get port from url
query, q Get query from url
fragment, f Get fragment from url
help, h Shows a list of commands or help for one command
2020-02-03 00:05:18 +01:00
GLOBAL OPTIONS:
--url value source url to parse [$URL_PARSER_URL]
2023-07-19 15:56:43 +02:00
--help, -h show help
--version, -v print the version
2020-02-03 00:05:18 +01:00
```
## Examples
```Shell
2023-07-19 15:56:43 +02:00
$ url-parser --url https://somedomain.com host
2020-02-03 00:05:18 +01:00
somedomain.com
2023-07-19 15:56:43 +02:00
$ url-parser --url https://herloct@somedomain.com user
2020-02-03 00:05:18 +01:00
herloct
2023-07-19 15:56:43 +02:00
$ url-parser --url https://somedomain.com/path/to path
2020-02-03 00:05:18 +01:00
/path/to
2023-07-19 15:56:43 +02:00
$ url-parser --url https://somedomain.com/path/to path --path-index=1
2020-02-03 00:05:18 +01:00
to
2023-07-19 15:56:43 +02:00
$ url-parser --url https://somedomain.com/?some-key=somevalue query
2020-02-03 00:05:18 +01:00
some-key=somevalue
2023-07-19 15:56:43 +02:00
$ url-parser --url https://somedomain.com/?some-key=somevalue query --query-field=some-key
2020-02-03 00:05:18 +01:00
somevalue
2023-07-23 10:02:46 +02:00
# It is also possible to read the URL from stdin
$ echo "https://somedomain.com" | url-parser host
somedomain.com
2020-02-03 00:05:18 +01:00
```
2020-09-21 20:54:34 +02:00
## Contributors
2022-07-12 09:12:32 +02:00
Special thanks to all [contributors ](https://github.com/thegeeklab/url-parser/graphs/contributors ). If you would like to contribute, please see the [instructions ](https://github.com/thegeeklab/url-parser/blob/main/CONTRIBUTING.md ).
2020-09-21 20:54:34 +02:00
2020-02-24 22:26:37 +01:00
## License
2020-02-03 00:05:18 +01:00
2021-01-04 16:49:49 +01:00
This project is licensed under the MIT License - see the [LICENSE ](https://github.com/thegeeklab/url-parser/blob/main/LICENSE ) file for details.