Skip to content

Commit

Permalink
Merge pull request #19 from kellyjonbrazil/dev
Browse files Browse the repository at this point in the history
Dev v1.4.0
  • Loading branch information
kellyjonbrazil committed Jun 19, 2021
2 parents 11f5282 + daec2cf commit 7824f15
Show file tree
Hide file tree
Showing 14 changed files with 881 additions and 867 deletions.
46 changes: 16 additions & 30 deletions ADVANCED_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ The file must be named `.jelloconf.py` and must be located in the proper directo
- Windows: `%appdata%/`

##### Setting Options
To set `jello` options in the `.jelloconf.py` file, add any of the following and set to `True` or `False`:
To set `jello` options in the `.jelloconf.py` file, import the `jello.lib.opts` class, add any of the following and set to `True` or `False`:
```
mono = True # -m option
compact = True # -c option
lines = True # -l option
raw = True # -r option
nulls = True # -n option
schema = True # -s option
from jello.lib import opts
opts.mono = True # -m option
opts.compact = True # -c option
opts.lines = True # -l option
opts.raw = True # -r option
opts.nulls = True # -n option
opts.schema = True # -s option
opts.types = True # -t option
```
##### Setting Colors
You can customize the colors by setting the following variables to one of the following string values: `'black'`, `'red'`, `'green'`, `'yellow'`, `'blue'`, `'magenta'`, `'cyan'`, `'gray'`, `'brightblack'`, `'brightred'`, `'brightgreen'`, `'brightyellow'`, `'brightblue'`, `'brightmagenta'`, `'brightcyan'`, or `'white'`.
You can customize the colors by importing the `jello.lib.opts` class and setting the following variables to one of the following string values: `'black'`, `'red'`, `'green'`, `'yellow'`, `'blue'`, `'magenta'`, `'cyan'`, `'gray'`, `'brightblack'`, `'brightred'`, `'brightgreen'`, `'brightyellow'`, `'brightblue'`, `'brightmagenta'`, `'brightcyan'`, or `'white'`.
```
keyname_color = 'blue' # Key names
keyword_color = 'brightblack' # true, false, null
number_color = 'magenta' # integers, floats
string_color = 'green' # strings
arrayid_color = 'red' # array IDs in Schema view
arraybracket_color = 'magenta' # array brackets in Schema view
from jello.lib import opts
opts.keyname_color = 'blue' # Key names
opts.keyword_color = 'brightblack' # true, false, null
opts.number_color = 'magenta' # integers, floats
opts.string_color = 'green' # strings
```
> Note: Any colors set via the `JELLO_COLORS` environment variable will take precedence over any color values set in the `.jelloconf.py` configuration file
Expand Down Expand Up @@ -61,20 +62,5 @@ jc -a | jello -i 'g("parsers.6.compatible")'
"freebsd"
]
```
## Setting Custom Colors via Environment Variable
In addition to setting custom colors in the `.jelloconf.py` intialization file, you can also set them via the `JELLO_COLORS` environment variable. Any colors set in the environment variable will take precedence over any colors set in the initialization file.

The `JELLO_COLORS` environment variable takes six comma separated string values in the following format:
```
JELLO_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>,<arrayid_color>,<arraybracket_color>
```
Where colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`, `brightmagenta`, `brightcyan`, `white`, or `default`

For example, to set to the default colors:
```
JELLO_COLORS=blue,brightblack,magenta,green,red,magenta
```
or
```
JELLO_COLORS=default,default,default,default,default,default
```
> Tip: Add a line to print a message to STDERR in your `.jelloconf.py` file to show when the initialization file is being used: `print('Running initialization file', file=sys.stderr)`
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
jello changelog

20210614 v1.4.0
- Add type annotation option for Schema view
- Enhance error handling when a dict method is accessed (e.g. .get)
- Enhance exception error messages
- Pygments library dependency is now optional
- Code refactor to split cli from lib

20210609 v1.3.6
- Documentation fixes for packages and binaries hosting

Expand Down
84 changes: 65 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cat data.json | jello '_["foo"]'
- `-n` print selected `null` values
- `-r` raw output of selected strings (no quotes)
- `-s` print the JSON schema in grep-able format
- `-t` print type annotations in schema view
- `-h` help
- `-v` version info

Expand Down Expand Up @@ -89,15 +90,15 @@ echo '{"foo":"bar","baz":[1,2,3]}' | jello -l _.baz
3
```

You can also create [JSON Lines](https://jsonlines.org/) with the `-l` option:
The `-l` option also allows you to create [JSON Lines](https://jsonlines.org/):
```bash
echo '[{"foo":"bar","baz":[1,2,3]},{"foo":"bar","baz":[1,2,3]}]' | jello -l
echo '[{"foo":"bar","baz":[1,2,3]},{"fiz":"boo","buz":[4,5,6]}]' | jello -l

{"foo":"bar","baz":[1,2,3]}
{"foo":"bar","baz":[1,2,3]}
{"fiz":"boo","buz":[4,5,6]}
```

You can also print a grep-able schema by using the `-s` option:
You can print a grep-able schema by using the `-s` option:
```bash
echo '{"foo":"bar","baz":[1,2,3]}' | jello -s

Expand All @@ -109,7 +110,7 @@ echo '{"foo":"bar","baz":[1,2,3]}' | jello -s

#### Assigning Results to a Bash Array

Use the `-l` option to print JSON array output in a manner suitable to be assigned to a bash array. The `-r` option can be used to remove quotation marks around strings. If you want `null` values to be printed as `null`, use the `-n` option, otherwise they are blank lines.
Use the `-l` option to print JSON array output in a manner suitable to be assigned to a bash array. The `-r` option can be used to remove quotation marks around strings. If you want `null` values to be printed as `null`, use the `-n` option, otherwise they are printed as blank lines.

Bash variable:
```
Expand All @@ -124,30 +125,75 @@ while read -r value; do
done < <(cat data.json | jello -rl _.foo)
```

Here is more [advanced usage](https://github.com/kellyjonbrazil/jello/blob/master/ADVANCED_USAGE.md) information.
### Setting Custom Colors via Environment Variable
Custom colors can be set via the `JELLO_COLORS` environment variable. Any colors set in the environment variable will take precedence over any colors set in the initialization file. (see [Advanced Usage](https://github.com/kellyjonbrazil/jello/blob/master/ADVANCED_USAGE.md))

The `JELLO_COLORS` environment variable takes four comma separated string values in the following format:
```
JELLO_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
```
Where colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`, `brightmagenta`, `brightcyan`, `white`, or `default`

For example, to set to the default colors:
```
JELLO_COLORS=blue,brightblack,magenta,green
```
or
```
JELLO_COLORS=default,default,default,default
```

Here is more [Advanced Usage](https://github.com/kellyjonbrazil/jello/blob/master/ADVANCED_USAGE.md) information.

## Examples:
### Printing the Grep-able Schema
```bash
jc -a | jello -s

.name = "jc";
.version = "1.10.2";
.description = "jc cli output JSON conversion tool";
.version = "1.15.5";
.description = "JSON CLI output utility";
.author = "Kelly Brazil";
.author_email = "kellyjonbrazil@gmail.com";
.parser_count = 50;
.parsers[0].name = "airport";
.parsers[0].argument = "--airport";
.parsers[0].version = "1.0";
.parsers[0].description = "airport -I command parser";
.website = "https://github.com/kellyjonbrazil/jc";
.copyright = "© 2019-2021 Kelly Brazil";
.license = "MIT License";
.parser_count = 73;
.parsers[0].name = "acpi";
.parsers[0].argument = "--acpi";
.parsers[0].version = "1.2";
.parsers[0].description = "`acpi` command parser";
.parsers[0].author = "Kelly Brazil";
.parsers[0].author_email = "kellyjonbrazil@gmail.com";
.parsers[0].compatible[0] = "darwin";
.parsers[0].magic_commands[0] = "airport -I";
.parsers[1].name = "airport_s";
.parsers[1].argument = "--airport-s";
.parsers[1].version = "1.0";
.parsers[0].compatible[0] = "linux";
.parsers[0].magic_commands[0] = "acpi";
.parsers[1].name = "airport";
.parsers[1].argument = "--airport";
.parsers[1].version = "1.3";
...
```
### Printing the Grep-able Schema with type annotations (useful for grepping types)
```bash
jc -a | jello -st
.name = "jc"; // (string)
.version = "1.15.5"; // (string)
.description = "JSON CLI output utility"; // (string)
.author = "Kelly Brazil"; // (string)
.author_email = "kellyjonbrazil@gmail.com"; // (string)
.website = "https://github.com/kellyjonbrazil/jc"; // (string)
.copyright = "© 2019-2021 Kelly Brazil"; // (string)
.license = "MIT License"; // (string)
.parser_count = 73; // (number)
.parsers[0].name = "acpi"; // (string)
.parsers[0].argument = "--acpi"; // (string)
.parsers[0].version = "1.2"; // (string)
.parsers[0].description = "`acpi` command parser"; // (string)
.parsers[0].author = "Kelly Brazil"; // (string)
.parsers[0].author_email = "kellyjonbrazil@gmail.com"; // (string)
.parsers[0].compatible[0] = "linux"; // (string)
.parsers[0].magic_commands[0] = "acpi"; // (string)
.parsers[1].name = "airport"; // (string)
.parsers[1].argument = "--airport"; // (string)
.parsers[1].version = "1.3"; // (string)
...
```
### Lambda Functions and Math
Expand Down
8 changes: 8 additions & 0 deletions jello/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""jello - query JSON at the command line with python syntax"""


__version__ = '1.4.0'
AUTHOR = 'Kelly Brazil'
WEBSITE = 'https://github.com/kellyjonbrazil/jello'
COPYRIGHT = '© 2020-2021 Kelly Brazil'
LICENSE = 'MIT License'

0 comments on commit 7824f15

Please sign in to comment.