1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/templates/manpage_template

242 lines
7.9 KiB
Plaintext
Raw Normal View History

2022-03-04 13:27:39 -08:00
.TH jc 1 {{ today }} {{ jc.version}} "JSON Convert"
2021-04-02 17:40:09 -07:00
.SH NAME
2022-05-12 11:16:44 -07:00
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools and file-types
2021-04-02 17:40:09 -07:00
.SH SYNOPSIS
COMMAND | jc PARSER [OPTIONS]
or "Magic" syntax:
2021-04-04 14:29:37 -07:00
2022-05-12 11:16:44 -07:00
\fBjc\fP [OPTIONS] COMMAND
2021-04-02 17:40:09 -07:00
.SH DESCRIPTION
2022-05-12 11:16:44 -07:00
\fBjc\fP JSONifies the output of many CLI tools and file-types for easier parsing in scripts. \fBjc\fP accepts piped input from \fBSTDIN\fP and outputs a JSON representation of the previous command's output to \fBSTDOUT\fP. Alternatively, the "Magic" syntax can be used by prepending \fBjc\fP to the command to be converted. Options can be passed to \fBjc\fP immediately before the command is given. (Note: "Magic" syntax does not support shell builtins or command aliases)
2021-04-02 17:40:09 -07:00
.SH OPTIONS
.B
Parsers:
.RS
{% for parser in jc.parsers %}
.TP
.B
\fB{{ parser.argument }}\fP
{{ parser.description }}
{% endfor %}
.RE
.PP
.B
Options:
.RS
.TP
.B
\fB-a\fP
2022-05-23 13:43:57 -07:00
about \fBjc\fP (JSON or YAML output)
2021-04-02 17:40:09 -07:00
.TP
.B
2021-12-08 08:22:28 -08:00
\fB-C\fP
2021-12-08 11:21:12 -08:00
force color output even when using pipes (overrides \fB-m\fP and the \fBNO_COLOR\fP env variable)
2021-12-08 08:22:28 -08:00
.TP
.B
2021-04-02 17:40:09 -07:00
\fB-d\fP
2021-09-23 11:48:39 -07:00
debug - show traceback (use \fB-dd\fP for verbose traceback)
2021-04-02 17:40:09 -07:00
.TP
.B
2021-04-02 18:08:46 -07:00
\fB-h\fP
2021-04-16 08:46:20 -07:00
help (\fB-h --parser_name\fP for parser documentation)
2021-04-02 18:08:46 -07:00
.TP
.B
2021-04-02 17:40:09 -07:00
\fB-m\fP
monochrome output
.TP
.B
\fB-p\fP
pretty print output
.TP
.B
\fB-q\fP
2021-09-23 11:48:39 -07:00
quiet - suppress warnings (use \fB-qq\fP to ignore streaming parser errors)
2021-04-02 17:40:09 -07:00
.TP
.B
\fB-r\fP
raw JSON output
2021-04-02 18:08:46 -07:00
.TP
.B
\fB-u\fP
unbuffer output (useful for slow streaming data with streaming parsers)
.TP
.B
2021-04-02 18:08:46 -07:00
\fB-v\fP
version information
2022-05-23 13:43:57 -07:00
.TP
.B
\fB-y\fP
YAML output
2021-04-04 14:29:37 -07:00
2021-05-11 11:11:17 -07:00
.SH EXIT CODES
2022-05-12 11:16:44 -07:00
Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP. When using the "Magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP.
2021-05-11 11:11:17 -07:00
2021-12-08 11:21:12 -08:00
Consider the following examples using \fBifconfig\fP:
2021-05-11 11:11:17 -07:00
.RS
2021-05-11 11:32:08 -07:00
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
2021-05-11 11:11:17 -07:00
2021-05-11 11:32:08 -07:00
ifconfig exit code = \fB1\fP, jc exit code = \fB0\fP, combined exit code = \fB1\fP (error in ifconfig)
2021-05-11 11:11:17 -07:00
2021-05-11 11:32:08 -07:00
ifconfig exit code = \fB0\fP, jc exit code = \fB100\fP, combined exit code = \fB100\fP (error in jc)
2021-05-11 11:11:17 -07:00
2021-05-11 11:32:08 -07:00
ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB101\fP (error in both ifconfig and jc)
2021-05-11 11:11:17 -07:00
.RE
2021-04-04 14:29:37 -07:00
.SH ENVIRONMENT
2021-12-08 08:35:09 -08:00
\fBCustom Colors\fP
2021-04-04 14:29:37 -07:00
You can specify custom colors via the \fBJC_COLORS\fP environment variable. The \fBJC_COLORS\fP environment variable takes four comma separated string values in the following format:
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
Where colors are: \fBblack\fP, \fBred\fP, \fBgreen\fP, \fByellow\fP, \fBblue\fP, \fBmagenta\fP, \fBcyan\fP, \fBgray\fP, \fBbrightblack\fP, \fBbrightred\fP, \fBbrightgreen\fP, \fBbrightyellow\fP, \fBbrightblue\fP, \fBbrightmagenta\fP, \fBbrightcyan\fP, \fBwhite\fP, or \fBdefault\fP
For example, to set to the default colors:
2021-04-04 14:40:22 -07:00
.RS
2021-04-04 14:29:37 -07:00
JC_COLORS=blue,brightblack,magenta,green
or
JC_COLORS=default,default,default,default
2021-04-04 14:40:22 -07:00
.RE
2021-04-04 14:29:37 -07:00
2021-12-08 08:35:09 -08:00
\fBDisable Color Output\fP
2022-05-12 11:16:44 -07:00
You can set the \fBNO_COLOR\fP environment variable to any value to disable color output in \fBjc\fP. Note that using the \fB-C\fP option to force color output will override both the \fBNO_COLOR\fP environment variable and the \fB-m\fP option.
2021-09-20 13:04:26 -07:00
.SH STREAMING PARSERS
2022-05-12 11:16:44 -07:00
Most parsers load all of the data from \fBSTDIN\fP, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. \fBls-s\fP, \fBping-s\fP, etc.) that immediately start processing and outputing the data line-by-line as JSON Lines (aka NDJSON) while it is being received from \fBSTDIN\fP. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. \fBls -lR /\fP) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
2021-09-20 13:04:26 -07:00
.RS
Note: Streaming parsers cannot be used with the "magic" syntax
.RE
\fBIgnoring Errors\fP
2021-09-23 13:07:10 -07:00
You may want to ignore parsing errors when using streaming parsers since these may be used in long-lived processing pipelines and errors can break the pipe. To ignore parsing errors, use the \fB-qq\fP cli option. This will add a \fB_jc_meta\fP object to the JSON output with a \fBsuccess\fP attribute. If \fBsuccess\fP is \fBtrue\fP, then there were no issues parsing the line. If \fBsuccess\fP is \fBfalse\fP, then a parsing issue was found and \fBerror\fP and \fBline\fP fields will be added to include a short error description and the contents of the unparsable line, respectively:
2021-09-20 13:04:26 -07:00
.RS
2021-09-23 11:54:58 -07:00
Successfully parsed line with \fB-qq\fP option:
2021-09-20 13:04:26 -07:00
.RS
2022-02-24 21:21:02 -08:00
.nf
2021-09-20 13:04:26 -07:00
{
"command_data": "data",
2021-09-23 13:07:10 -07:00
"_jc_meta": {
2021-09-20 13:04:26 -07:00
"success": true
}
}
2022-03-09 14:43:56 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
2021-09-23 11:54:58 -07:00
Unsuccessfully parsed line with \fB-qq\fP option:
2021-09-20 13:04:26 -07:00
.RS
2022-02-24 21:21:02 -08:00
.nf
2021-09-20 13:04:26 -07:00
{
2021-09-23 13:07:10 -07:00
"_jc_meta": {
2021-09-20 13:04:26 -07:00
"success": false,
2021-09-23 12:58:24 -07:00
"error": "error message",
2021-09-20 13:04:26 -07:00
"line": "original line data"
}
}
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
.RE
\fBUnbuffering Output\fP
Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fBping\fP):
.RS
2022-02-24 21:21:02 -08:00
.nf
2022-03-09 14:17:48 -08:00
$ ping 1.1.1.1 | jc \fB--ping-s\fP | jq
2021-09-20 13:04:26 -07:00
<slow output>
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
.RE
This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB-u\fP (unbuffer) cli option:
.RS
2022-02-24 21:21:02 -08:00
.nf
2022-03-09 14:17:48 -08:00
$ ping 1.1.1.1 | jc \fB--ping-s\fP \fB-u\fP | jq
2022-02-24 21:21:02 -08:00
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...}
2021-09-20 13:04:26 -07:00
etc...
2022-02-24 21:21:02 -08:00
.fi
2021-09-20 13:04:26 -07:00
2021-09-23 08:53:25 -07:00
Note: Unbuffered output can be slower for large data streams.
2021-09-20 13:04:26 -07:00
.RE
2021-04-04 14:29:37 -07:00
.SH CUSTOM PARSERS
Custom local parser plugins may be placed in a \fBjc/jcparsers\fP folder in your local "App data directory":
2021-04-04 14:40:22 -07:00
.RS
2022-03-09 14:17:48 -08:00
.nf
2021-04-04 14:29:37 -07:00
- Linux/unix: \fB$HOME/.local/share/jc/jcparsers\fP
- macOS: \fB$HOME/Library/Application Support/jc/jcparsers\fP
2021-04-04 14:40:22 -07:00
- Windows: \fB$LOCALAPPDATA\\jc\\jc\\jcparsers\fP
2022-03-09 14:17:48 -08:00
.fi
2021-04-04 14:40:22 -07:00
.RE
2021-04-04 14:29:37 -07:00
2022-05-12 11:16:44 -07:00
Local parser plugins are standard python module files. Use the \fBjc/parsers/foo.py\fP or \fBjc/parsers/foo_s.py\fP (streaming) parser as a template and simply place a \fB.py\fP file in the \fBjcparsers\fP subfolder.
2021-04-04 14:29:37 -07:00
2022-04-29 06:50:37 -07:00
Local plugin filenames must be valid python module names and therefore must start with a letter and consist entirely of alphanumerics and underscores. Local plugins may override default parsers.
2021-04-04 14:29:37 -07:00
Note: The application data directory follows the XDG Base Directory Specification
2021-04-25 20:55:43 -07:00
.SH CAVEATS
2022-05-12 11:16:44 -07:00
\fBLocale\fP
For best results set the \fBLANG\fP locale environment variable to \fBC\fP or \fBen_US.UTF-8\fP. For example, either by setting directly on the command-line:
2021-04-25 20:55:43 -07:00
2022-03-09 14:17:48 -08:00
.RS
$ LANG=C date | jc \fB--date\fP
.RE
2021-04-25 20:55:43 -07:00
or by exporting to the environment before running commands:
2022-03-09 14:17:48 -08:00
.RS
$ export LANG=C
.RE
2021-04-25 20:55:43 -07:00
2022-05-12 11:16:44 -07:00
On some older systems UTF-8 output will be downgraded to ASCII with \fB\\u\fP escape sequences if the \fBC\fP locale does not support UTF-8 encoding.
\fBTimezones\fP
2022-04-26 17:51:30 -07:00
2022-05-12 11:16:44 -07:00
Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a \fB_utc\fP suffix it is considered naive. (i.e. based on the local timezone of the system the \fBjc\fP parser was run on).
2021-04-25 20:55:43 -07:00
If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a \fB_utc\fP suffix on the key name. (e.g. \fBepoch_utc\fP) No other timezones are supported for aware timestamps.
2021-04-16 08:46:20 -07:00
.SH EXAMPLES
Standard Syntax:
.RS
$ dig www.google.com | jc \fB--dig\fP \fB-p\fP
.RE
2021-04-04 14:40:22 -07:00
2021-04-16 08:46:20 -07:00
Magic Syntax:
.RS
$ jc \fB-p\fP dig www.google.com
.RE
For parser documentation:
2021-04-16 08:46:20 -07:00
.RS
$ jc \fB-h\fP \fB--dig\fP
.RE
2021-04-04 14:40:22 -07:00
.SH AUTHOR
{{ jc.author }} ({{ jc.author_email }})
2021-04-04 14:40:22 -07:00
{{ jc.website }}
2021-04-04 14:40:22 -07:00
.SH COPYRIGHT
Copyright (c) {{ jc.copyright[2:] }}
2021-04-04 14:40:22 -07:00
License: {{ jc.license }}