xh/doc/man-template.roff
Jan Verbeek 41ab47f32f Add --debug option for logging and backtraces
Add `env_logger` to be able to print the logs that our libraries
already generate.

Add some logging to the application code. We'll probably want more log
messages, and we might want to upgrade some of them from trace to
debug.

Add a `--debug` flag that automatically enables `env_logger` as well
as backtraces for `anyhow` and panics.

```console
$ xh --debug :
[2024-06-05T13:54:40Z DEBUG xh] xh 0.22.0 -native-tls +rustls
[2024-06-05T13:54:40Z DEBUG xh] Cli {
        httpie_compat_mode: false,
        [...]
    }
[2024-06-05T13:54:40Z DEBUG xh] Complete URL: http://localhost/
[2024-06-05T13:54:40Z DEBUG xh] HTTP method: GET
[2024-06-05T13:54:40Z DEBUG reqwest::connect] starting new connection: http://localhost/
[2024-06-05T13:54:40Z DEBUG hyper_util::client::legacy::connect::dns] resolving host="localhost"
[...]
xh: error: error sending request for url (http://localhost/)

Caused by:
    0: client error (Connect)
    1: tcp connect error: Connection refused (os error 111)
    2: Connection refused (os error 111)

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.82/src/error.rs:565:25
[...]
```

We could ask users to post `--debug` output when reporting bugs.
2024-06-05 17:47:36 +02:00

156 lines
3.8 KiB
Plaintext

.TH XH 1 {{date}} {{version}} "User Commands"
.SH NAME
xh \- Friendly and fast tool for sending HTTP requests
.SH SYNOPSIS
.B xh
[\fIOPTIONS\fR]
[\fIMETHOD\fR]
\fIURL\fR
[\-\-\]
[\fIREQUEST_ITEM\fR ...]
.SH DESCRIPTION
\fBxh\fR is an HTTP client with a friendly command line interface. It strives to
have readable output and easy-to-use options.
xh is mostly compatible with HTTPie: see \fBhttp\fR(1).
The \fB--curl\fR option can be used to print a \fBcurl\fR(1) translation of the
command instead of sending a request.
.SH POSITIONAL ARGUMENTS
.TP 4
[\fIMETHOD\fR]\fI
The HTTP method to use for the request.
This defaults to GET, or to POST if the request contains a body.
.TP
\fIURL\fR
The URL to request.
The URL scheme defaults to "http://" normally, or "https://" if
the program is invoked as "xhs".
A leading colon works as shorthand for localhost. ":8000" is equivalent
to "localhost:8000", and ":/path" is equivalent to "localhost/path".
.TP
[\fIREQUEST_ITEM\fR ...]
{{request_items}}
.SH OPTIONS
Each --OPTION can be reset with a --no-OPTION argument.
{{options}}
.SH EXIT STATUS
.TP 4
.B 0
Successful program execution.
.TP
.B 1
Usage, syntax or network error.
.TP
.B 2
Request timeout.
.TP
.B 3
Unexpected HTTP 3xx Redirection.
.TP
.B 4
HTTP 4xx Client Error.
.TP
.B 5
HTTP 5xx Server Error.
.TP
.B 6
Too many redirects.
.SH ENVIRONMENT
.TP 4
.B XH_CONFIG_DIR
Specifies where to look for config.json and named session data.
The default is ~/.config/xh for Linux/macOS and %APPDATA%\\xh for Windows.
.TP
.B XH_HTTPIE_COMPAT_MODE
Enables the HTTPie Compatibility Mode. The only current difference is that
\-\-check-status is not enabled by default. An alternative to setting this
environment variable is to rename the binary to either http or https.
.TP
.BR REQUESTS_CA_BUNDLE ", " CURL_CA_BUNDLE
Sets a custom CA bundle path.
.TP
.BR http_proxy "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTP.
.TP
.BR HTTPS_PROXY "=[protocol://]<host>[:port]"
Sets the proxy server to use for HTTPS.
.TP
.B NO_PROXY
List of comma-separated hosts for which to ignore the other proxy environment
variables. "*" matches all host names.
.TP
.B NETRC
Location of the .netrc file.
.TP
.B NO_COLOR
Disables output coloring. See <https://no-color.org>
.TP
.B RUST_LOG
Configure low-level debug messages. See <https://docs.rs/env_logger/0.11.3/env_logger/#enabling-logging>
.SH FILES
.TP 4
.I ~/.config/xh/config.json
xh configuration file. The only configurable option is "default_options"
which is a list of default shell arguments that gets passed to xh.
Example:
.RS
{ "default_options": ["--native-tls", "--style=solarized"] }
.RE
.TP
.IR ~/.netrc ", " ~/_netrc
Auto-login information file.
.TP
.I ~/.config/xh/sessions
Session data directory grouped by domain and port number.
.SH EXAMPLES
.TP 4
\fBxh\fR \fIhttpbin.org/json\fR
Send a GET request.
.TP
\fBxh\fR \fIhttpbin.org/post name=ahmed \fIage:=24\fR
Send a POST request with body {"name": "ahmed", "age": 24}.
.TP
\fBxh\fR get \fIhttpbin.org/json id==5 sort==true\fR
Send a GET request to http://httpbin.org/json?id=5&sort=true.
.TP
\fBxh\fR get \fIhttpbin.org/json x-api-key:12345\fR
Send a GET request and include a header named X-Api-Key with value 12345.
.TP
echo "[1, 2, 3]" | \fBxh\fR post \fIhttpbin.org/post
Send a POST request with body read from stdin.
.TP
\fBxh\fR put \fIhttpbin.org/put id:=49 age:=25\fR | less
Send a PUT request and pipe the result to less.
.TP
\fBxh\fR -d \fIhttpbin.org/json\fR -o \fIres.json\fR
Download and save to res.json.
.TP
\fBxh\fR \fIhttpbin.org/get user-agent:foobar\fR
Make a request with a custom user agent.
.TP
\fBxhs\fR \fIexample.com\fR
Make an HTTPS request to https://example.com.
.SH REPORTING BUGS
xh's Github issues <https://github.com/ducaale/xh/issues>
.SH SEE ALSO
\fBcurl\fR(1), \fBhttp\fR(1)
HTTPie's online documentation <https://httpie.io/docs/cli>