mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
@ -1,5 +1,9 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
|
20211207 v1.17.4
|
||||||
|
- Add support for the NO_COLOR environment variable to set mono (http://no-color.org/)
|
||||||
|
- Add -C option to force color output even when using pipes (overrides -m and NO_COLOR)
|
||||||
|
|
||||||
20211202 v1.17.3
|
20211202 v1.17.3
|
||||||
- Update parsers to exit with error if non-string input is detected (raise TypeError)
|
- Update parsers to exit with error if non-string input is detected (raise TypeError)
|
||||||
- Update streaming parsers to exit with error if non-iterable input is detected (raise TypeError)
|
- Update streaming parsers to exit with error if non-iterable input is detected (raise TypeError)
|
||||||
|
@ -191,6 +191,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
|
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
|
||||||
|
- `-C` force color output even when using pipes (overrides `-m` and the `NO_COLOR` env variable)
|
||||||
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
|
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
|
||||||
- `-h` help. Use `jc -h --parser_name` for parser documentation
|
- `-h` help. Use `jc -h --parser_name` for parser documentation
|
||||||
- `-m` monochrome JSON output
|
- `-m` monochrome JSON output
|
||||||
@ -229,6 +230,9 @@ or
|
|||||||
JC_COLORS=default,default,default,default
|
JC_COLORS=default,default,default,default
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Disable Colors via Environment Variable
|
||||||
|
You can set the [`NO_COLOR`](http://no-color.org/) environment variable to any value to disable color output in `jc`. Note that using the `-C` option to force color output will override both the `NO_COLOR` environment variable and the `-m` option.
|
||||||
|
|
||||||
### Streaming Parsers
|
### Streaming Parsers
|
||||||
Most parsers load all of the data from STDIN, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. `ls-s` and `ping-s`) that immediately start processing and outputing the data line-by-line as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while it is being received from STDIN. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. `ls -lR /`) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
|
Most parsers load all of the data from STDIN, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. `ls-s` and `ping-s`) that immediately start processing and outputing the data line-by-line as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while it is being received from STDIN. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. `ls -lR /`) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
|
||||||
|
|
||||||
|
@ -73,4 +73,4 @@ Module Example:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
name = 'jc'
|
name = 'jc'
|
||||||
__version__ = '1.17.3'
|
__version__ = '1.17.4'
|
||||||
|
22
jc/cli.py
22
jc/cli.py
@ -235,9 +235,11 @@ def set_env_colors(env_colors=None):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def piped_output():
|
def piped_output(force_color):
|
||||||
"""Return False if stdout is a TTY. True if output is being piped to another program"""
|
"""Return False if stdout is a TTY. True if output is being piped to another program
|
||||||
return not sys.stdout.isatty()
|
and foce_color is True. This allows forcing of ANSI color codes even when using pipes.
|
||||||
|
"""
|
||||||
|
return not sys.stdout.isatty() and not force_color
|
||||||
|
|
||||||
|
|
||||||
def ctrlc(signum, frame):
|
def ctrlc(signum, frame):
|
||||||
@ -335,6 +337,7 @@ def helptext():
|
|||||||
{parsers_string}
|
{parsers_string}
|
||||||
Options:
|
Options:
|
||||||
-a about jc
|
-a about jc
|
||||||
|
-C force color output even when using pipes (overrides -m)
|
||||||
-d debug (-dd for verbose debug)
|
-d debug (-dd for verbose debug)
|
||||||
-h help (-h --parser_name for parser documentation)
|
-h help (-h --parser_name for parser documentation)
|
||||||
-m monochrome output
|
-m monochrome output
|
||||||
@ -526,7 +529,8 @@ def main():
|
|||||||
about = 'a' in options
|
about = 'a' in options
|
||||||
debug = 'd' in options
|
debug = 'd' in options
|
||||||
verbose_debug = options.count('d') > 1
|
verbose_debug = options.count('d') > 1
|
||||||
mono = 'm' in options
|
force_color = 'C' in options
|
||||||
|
mono = ('m' in options or bool(os.getenv('NO_COLOR'))) and not force_color
|
||||||
help_me = 'h' in options
|
help_me = 'h' in options
|
||||||
pretty = 'p' in options
|
pretty = 'p' in options
|
||||||
quiet = 'q' in options
|
quiet = 'q' in options
|
||||||
@ -542,7 +546,11 @@ def main():
|
|||||||
mono = True
|
mono = True
|
||||||
|
|
||||||
if about:
|
if about:
|
||||||
print(json_out(about_jc(), pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
print(json_out(about_jc(),
|
||||||
|
pretty=pretty,
|
||||||
|
env_colors=jc_colors,
|
||||||
|
mono=mono,
|
||||||
|
piped_out=piped_output(force_color)))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if help_me:
|
if help_me:
|
||||||
@ -632,7 +640,7 @@ def main():
|
|||||||
pretty=pretty,
|
pretty=pretty,
|
||||||
env_colors=jc_colors,
|
env_colors=jc_colors,
|
||||||
mono=mono,
|
mono=mono,
|
||||||
piped_out=piped_output()),
|
piped_out=piped_output(force_color)),
|
||||||
flush=unbuffer)
|
flush=unbuffer)
|
||||||
|
|
||||||
sys.exit(combined_exit_code(magic_exit_code, 0))
|
sys.exit(combined_exit_code(magic_exit_code, 0))
|
||||||
@ -645,7 +653,7 @@ def main():
|
|||||||
pretty=pretty,
|
pretty=pretty,
|
||||||
env_colors=jc_colors,
|
env_colors=jc_colors,
|
||||||
mono=mono,
|
mono=mono,
|
||||||
piped_out=piped_output()),
|
piped_out=piped_output(force_color)),
|
||||||
flush=unbuffer)
|
flush=unbuffer)
|
||||||
|
|
||||||
sys.exit(combined_exit_code(magic_exit_code, 0))
|
sys.exit(combined_exit_code(magic_exit_code, 0))
|
||||||
|
14
man/jc.1
14
man/jc.1
@ -1,4 +1,4 @@
|
|||||||
.TH jc 1 2021-12-02 1.17.3 "JSON CLI output utility"
|
.TH jc 1 2021-12-08 1.17.4 "JSON CLI output utility"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
jc \- JSONifies the output of many CLI tools and file-types
|
jc \- JSONifies the output of many CLI tools and file-types
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -440,6 +440,10 @@ Options:
|
|||||||
about jc (JSON output)
|
about jc (JSON output)
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
|
\fB-C\fP
|
||||||
|
force color output even when using pipes (overrides \fB-m\fP and the \fBNO_COLOR\fP env variable)
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
\fB-d\fP
|
\fB-d\fP
|
||||||
debug - show traceback (use \fB-dd\fP for verbose traceback)
|
debug - show traceback (use \fB-dd\fP for verbose traceback)
|
||||||
.TP
|
.TP
|
||||||
@ -474,7 +478,7 @@ version information
|
|||||||
.SH EXIT CODES
|
.SH EXIT CODES
|
||||||
Any fatal errors within jc 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), jc will store the exit code of the program being parsed and add it to the jc exit code. This way it is easier to determine if an error was from the parsed program or jc.
|
Any fatal errors within jc 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), jc will store the exit code of the program being parsed and add it to the jc exit code. This way it is easier to determine if an error was from the parsed program or jc.
|
||||||
|
|
||||||
Consider the following examples using `ifconfig`:
|
Consider the following examples using \fBifconfig\fP:
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
|
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
|
||||||
@ -487,6 +491,9 @@ ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB
|
|||||||
.RE
|
.RE
|
||||||
|
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
|
|
||||||
|
\fBCustom Colors\fP
|
||||||
|
|
||||||
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:
|
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>
|
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
|
||||||
@ -503,6 +510,9 @@ or
|
|||||||
JC_COLORS=default,default,default,default
|
JC_COLORS=default,default,default,default
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
\fBDisable Color Output\fP
|
||||||
|
|
||||||
|
You can set the \fBNO_COLOR\fB 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.
|
||||||
|
|
||||||
.SH STREAMING PARSERS
|
.SH STREAMING PARSERS
|
||||||
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 and \fBping-s\fP) 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.
|
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 and \fBping-s\fP) 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.
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='jc',
|
name='jc',
|
||||||
version='1.17.3',
|
version='1.17.4',
|
||||||
author='Kelly Brazil',
|
author='Kelly Brazil',
|
||||||
author_email='kellyjonbrazil@gmail.com',
|
author_email='kellyjonbrazil@gmail.com',
|
||||||
description='Converts the output of popular command-line tools and file-types to JSON.',
|
description='Converts the output of popular command-line tools and file-types to JSON.',
|
||||||
|
@ -35,6 +35,10 @@ Options:
|
|||||||
about jc (JSON output)
|
about jc (JSON output)
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
|
\fB-C\fP
|
||||||
|
force color output even when using pipes (overrides \fB-m\fP and the \fBNO_COLOR\fP env variable)
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
\fB-d\fP
|
\fB-d\fP
|
||||||
debug - show traceback (use \fB-dd\fP for verbose traceback)
|
debug - show traceback (use \fB-dd\fP for verbose traceback)
|
||||||
.TP
|
.TP
|
||||||
@ -69,7 +73,7 @@ version information
|
|||||||
.SH EXIT CODES
|
.SH EXIT CODES
|
||||||
Any fatal errors within jc 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), jc will store the exit code of the program being parsed and add it to the jc exit code. This way it is easier to determine if an error was from the parsed program or jc.
|
Any fatal errors within jc 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), jc will store the exit code of the program being parsed and add it to the jc exit code. This way it is easier to determine if an error was from the parsed program or jc.
|
||||||
|
|
||||||
Consider the following examples using `ifconfig`:
|
Consider the following examples using \fBifconfig\fP:
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
|
ifconfig exit code = \fB0\fP, jc exit code = \fB0\fP, combined exit code = \fB0\fP (no errors)
|
||||||
@ -82,6 +86,9 @@ ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB
|
|||||||
.RE
|
.RE
|
||||||
|
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT
|
||||||
|
|
||||||
|
\fBCustom Colors\fP
|
||||||
|
|
||||||
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:
|
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>
|
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
|
||||||
@ -98,6 +105,9 @@ or
|
|||||||
JC_COLORS=default,default,default,default
|
JC_COLORS=default,default,default,default
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
|
\fBDisable Color Output\fP
|
||||||
|
|
||||||
|
You can set the \fBNO_COLOR\fB 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.
|
||||||
|
|
||||||
.SH STREAMING PARSERS
|
.SH STREAMING PARSERS
|
||||||
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 and \fBping-s\fP) 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.
|
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 and \fBping-s\fP) 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.
|
||||||
|
@ -110,6 +110,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
|
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
|
||||||
|
- `-C` force color output even when using pipes (overrides `-m` and the `NO_COLOR` env variable)
|
||||||
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
|
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
|
||||||
- `-h` help. Use `jc -h --parser_name` for parser documentation
|
- `-h` help. Use `jc -h --parser_name` for parser documentation
|
||||||
- `-m` monochrome JSON output
|
- `-m` monochrome JSON output
|
||||||
@ -148,6 +149,9 @@ or
|
|||||||
JC_COLORS=default,default,default,default
|
JC_COLORS=default,default,default,default
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Disable Colors via Environment Variable
|
||||||
|
You can set the [`NO_COLOR`](http://no-color.org/) environment variable to any value to disable color output in `jc`. Note that using the `-C` option to force color output will override both the `NO_COLOR` environment variable and the `-m` option.
|
||||||
|
|
||||||
### Streaming Parsers
|
### Streaming Parsers
|
||||||
Most parsers load all of the data from STDIN, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. `ls-s` and `ping-s`) that immediately start processing and outputing the data line-by-line as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while it is being received from STDIN. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. `ls -lR /`) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
|
Most parsers load all of the data from STDIN, parse it, then output the entire JSON document serially. There are some streaming parsers (e.g. `ls-s` and `ping-s`) that immediately start processing and outputing the data line-by-line as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while it is being received from STDIN. This can significantly reduce the amount of memory required to parse large amounts of command output (e.g. `ls -lR /`) and can sometimes process the data more quickly. Streaming parsers have slightly different behavior than standard parsers as outlined below.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user