Skip to content

Commit

Permalink
Merge pull request #209 from kellyjonbrazil/dev
Browse files Browse the repository at this point in the history
Dev v1.18.4
  • Loading branch information
kellyjonbrazil authored Mar 5, 2022
2 parents 961968a + 9861983 commit 6afb1d3
Show file tree
Hide file tree
Showing 230 changed files with 1,764 additions and 309 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
jc changelog

20220304 v1.18.4
- Add nmcli command parser tested on linux
- Enhance parse error messages at the cli
- Add standard and streaming parser list functions to the public API
- Enhance python developer documentation formatting

20220214 v1.18.3
- Add rsync command and log file parser tested on linux and macOS
- Add rsync command and log file streaming parser tested on linux and macOS
Expand Down
41 changes: 41 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,47 @@ netstat -i | jc --netstat -p # or: jc -p netstat -i
}
]
```
### nmcli
```bash
nmcli connection show ens33 | jc --nmcli -p # or jc -p nmcli connection show ens33
```
```json
[
{
"connection_id": "ens33",
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
"connection_stable_id": null,
"connection_type": "802-3-ethernet",
"connection_interface_name": "ens33",
"connection_autoconnect": "yes",
"ip4_address_1": "192.168.71.180/24",
"ip4_gateway": "192.168.71.2",
"ip4_route_1": {
"dst": "0.0.0.0/0",
"nh": "192.168.71.2",
"mt": 100
},
"ip4_route_2": {
"dst": "192.168.71.0/24",
"nh": "0.0.0.0",
"mt": 100
},
"ip4_dns_1": "192.168.71.2",
"ip4_domain_1": "localdomain",
"dhcp4_option_1": {
"name": "broadcast_address",
"value": "192.168.71.255"
},
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
"ip6_gateway": null,
"ip6_route_1": {
"dst": "fe80::/64",
"nh": "::",
"mt": 100
}
}
]
```
### ntpq
```bash
ntpq -p | jc --ntpq -p # or: jc -p ntpq -p
Expand Down
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master)
![Pypi](https://img.shields.io/pypi/v/jc.svg)

> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89)
> Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers
> Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/)
Expand All @@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this
for an example.

# JC
JSON CLI output utility
JSON Convert

`jc` JSONifies the output of many CLI tools and file-types for easier parsing in
scripts. See the [**Parsers**](#parsers) section for supported commands and
Expand Down Expand Up @@ -55,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON:
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> data = jc.parse('dig', cmd_output)
>>>
>>> data
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd',
'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num':
1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}},
'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer':
>>> data[0]['answer']
[{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data':
'93.184.216.34'}], 'query_time': 52, 'server':
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when':
'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, 'when_epoch': 1618614780,
'when_epoch_utc': None}]
'93.184.216.34'}]
```

> For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or
Expand Down Expand Up @@ -199,6 +190,7 @@ option.
- `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb))
- `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount))
- `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat))
- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli))
- `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq))
- `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd))
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
Expand Down
8 changes: 4 additions & 4 deletions docgen.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Generate docs.md
# requires pydoc-markdown 4.5.0
# requires pydoc-markdown 4.6.1
readme_config=$(cat <<'EOF'
{
"processors": [
Expand All @@ -18,7 +18,7 @@ readme_config=$(cat <<'EOF'
"Class": 3,
"Method": 3,
"Function": 3,
"Data": 3
"Variable": 3
}
}
}
Expand All @@ -43,7 +43,7 @@ toc_config=$(cat <<'EOF'
"Class": 3,
"Method": 3,
"Function": 3,
"Data": 3
"Variable": 3
}
}
}
Expand All @@ -68,7 +68,7 @@ parser_config=$(cat <<'EOF'
"Class": 3,
"Method": 3,
"Function": 3,
"Data": 3
"Variable": 3
}
}
}
Expand Down
38 changes: 33 additions & 5 deletions docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* [parse](#jc.lib.parse)
* [parser\_mod\_list](#jc.lib.parser_mod_list)
* [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list)
* [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list)
* [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list)
* [parser\_info](#jc.lib.parser_info)
* [all\_parser\_info](#jc.lib.all_parser_info)
* [get\_help](#jc.lib.get_help)
Expand All @@ -12,15 +14,20 @@

# jc.lib

jc - JSON CLI output utility
jc - JSON Convert
JC lib module

<a id="jc.lib.parse"></a>

### parse

```python
def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: bool = None, **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
def parse(parser_mod_name: str,
data: Union[str, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
```

Parse the string data using the supplied parser module.
Expand All @@ -34,9 +41,7 @@ Example:
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}

To get a list of available parser module names, use `parser_mod_list()`
or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset
of `parser_mod_list()`.
To get a list of available parser module names, use `parser_mod_list()`.

You can also use the lower-level parser modules directly:

Expand Down Expand Up @@ -100,6 +105,29 @@ def plugin_parser_mod_list() -> List[str]
Returns a list of plugin parser module names. This function is a
subset of `parser_mod_list()`.

<a id="jc.lib.standard_parser_mod_list"></a>

### standard\_parser\_mod\_list

```python
def standard_parser_mod_list() -> List[str]
```

Returns a list of standard parser module names. This function is a
subset of `parser_mod_list()` and does not contain any streaming
parsers.

<a id="jc.lib.streaming_parser_mod_list"></a>

### streaming\_parser\_mod\_list

```python
def streaming_parser_mod_list() -> List[str]
```

Returns a list of streaming parser module names. This function is a
subset of `parser_mod_list()`.

<a id="jc.lib.parser_info"></a>

### parser\_info
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/acpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.acpi

jc - JSON CLI output utility `acpi` command output parser
jc - JSON Convert `acpi` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/airport.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.airport

jc - JSON CLI output utility `airport -I` command output parser
jc - JSON Convert `airport -I` command output parser

The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/airport_s.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.airport\_s

jc - JSON CLI output utility `airport -s` command output parser
jc - JSON Convert `airport -s` command output parser

The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/arp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.arp

jc - JSON CLI output utility `arp` command output parser
jc - JSON Convert `arp` command output parser

Supports `arp` and `arp -a` output.

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/blkid.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.blkid

jc - JSON CLI output utility `blkid` command output parser
jc - JSON Convert `blkid` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/cksum.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.cksum

jc - JSON CLI output utility `cksum` command output parser
jc - JSON Convert `cksum` command output parser

This parser works with the following checksum calculation utilities:
- `sum`
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/crontab.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.crontab

jc - JSON CLI output utility `crontab -l` command output and crontab
jc - JSON Convert `crontab -l` command output and crontab
file parser

Supports `crontab -l` command output and crontab files.
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/crontab_u.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.crontab\_u

jc - JSON CLI output utility `crontab -l` command output and crontab
jc - JSON Convert `crontab -l` command output and crontab
file parser

This version of the `crontab -l` parser supports output that contains user
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.csv

jc - JSON CLI output utility `csv` file parser
jc - JSON Convert `csv` file parser

The `csv` parser will attempt to automatically detect the delimiter
character. If the delimiter cannot be detected it will default to comma.
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/csv_s.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.csv\_s

jc - JSON CLI output utility `csv` file streaming parser
jc - JSON Convert `csv` file streaming parser

> This streaming parser outputs JSON Lines
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.date

jc - JSON CLI output utility `date` command output parser
jc - JSON Convert `date` command output parser

The `epoch` calculated timestamp field is naive. (i.e. based on the local
time of the system the parser is run on)
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/df.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.df

jc - JSON CLI output utility `df` command output parser
jc - JSON Convert `df` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/dig.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.dig

jc - JSON CLI output utility `dig` command output parser
jc - JSON Convert `dig` command output parser

Options supported:
- `+noall +answer` options are supported in cases where only the answer
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.dir

jc - JSON CLI output utility `dir` command output parser
jc - JSON Convert `dir` command output parser

Options supported:
- `/T timefield`
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/dmidecode.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.dmidecode

jc - JSON CLI output utility `dmidecode` command output parser
jc - JSON Convert `dmidecode` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/dpkg_l.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.dpkg\_l

jc - JSON CLI output utility `dpkg -l` command output parser
jc - JSON Convert `dpkg -l` command output parser

Set the `COLUMNS` environment variable to a large value to avoid field
truncation. For example:
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/du.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.du

jc - JSON CLI output utility `du` command output parser
jc - JSON Convert `du` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.env

jc - JSON CLI output utility `env` and `printenv` command output parser
jc - JSON Convert `env` and `printenv` command output parser

This parser will output a list of dictionaries each containing `name` and
`value` keys. If you would like a simple dictionary output, then use the
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.file

jc - JSON CLI output utility `file` command output parser
jc - JSON Convert `file` command output parser

Usage (cli):

Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/finger.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# jc.parsers.finger

jc - JSON CLI output utility `finger` command output parser
jc - JSON Convert `finger` command output parser

Supports `-s` output option. Does not support the `-l` detail option.

Expand Down
Loading

0 comments on commit 6afb1d3

Please sign in to comment.