Skip to content

Command-line tool that helps with URI/URL handling and proper part extraction, escaping and parsing.

License

Notifications You must be signed in to change notification settings

adrianrudnik/uritool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uritool

Command-line tool that helps with URI/URL handling and proper part extraction, escaping and parsing.

license pipeline status coverage report go report card

Installation

The following methods are available:

Download

Directly download a version from the release page.

Snap

Install it on any system supporting snaps:

snap install uritool

Build yourself

Download the source code, review it and build it:

go test ./...
go build -mod=vendor .

This should build a local binary for your system with the name uritool in your current working directory.

Usage

Query commands

Encodes the given value to a valid query parameter value:

uritool query escape --no-newline "hello / world!%%"

# > hello+%2F+world%25%25

Decodes the given escaped query value:

uritool query unescape "hello+%2F+world%25%25"

# > hello / world!%%

Path commands

Escape the given value to a valid escaped path value:

uritool path escape "hello world"

# > hello%20world

Unescape the given escaped path value:

uritool path unescape "hello%20world"

# > hello world

Parse commands

Parse a given URI and return all information as JSON:

uritool parse uri "https://my:[email protected]:8080/what/ ever?this=is&this=isnot#doing"

# > {
# >   "Scheme": "https",
# >   "Opaque": "",
# >   "Username": "my",
# >   "Password": "pass",
# >   "PasswordIsGiven": true,
# >   "Host": "the.example.com:8080",
# >   "Hostname": "the.example.com",
# >   "Port": 8080,
# >   "Path": "/what/ ever",
# >   "PathEscaped": "/what/%20ever",
# >   "RawQuery": "this=is\u0026this=isnot",
# >   "Fragment": "doing",
# >   "Query": {
# >     "this": [
# >       "is",
# >       "isnot"
# >     ]
# >   }
# > }

But sometimes you just want a specific part or combination of it, so use can use the go template language:

uritool parse uri --format="Welcome {{.Username}} from {{.Hostname}}" "https://adrian:[email protected]:8080/?uh=oh"

# > Welcome adrian from the.example.com

uritool parse uri --format="Second entry is {{index .Query.things 1}}" "https://adrian:[email protected]:8080/?things=one&things=two"

# > Second entry is two

You can also parse query strings (leading "?" will be removed):

uritool parse query "?this=is&this=isnot"

# > {
# >   "this": [
# >     "is",
# >     "isnot"
# >   ]
# > }

This is also workable with the go template language:

uritool parse query -n --format="{{index .search 0}}" "search=mister&filter=x"

# > mister

About

Command-line tool that helps with URI/URL handling and proper part extraction, escaping and parsing.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages