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

move utils to own module and add quiet mode

This commit is contained in:
Kelly Brazil
2019-11-06 21:07:25 -08:00
parent 88dcb90c83
commit 9c1d893e16
4 changed files with 102 additions and 90 deletions

65
jc/utils.py Normal file
View File

@ -0,0 +1,65 @@
"""jc - JSON CLI output utility utils"""
import textwrap
import sys
def ctrlc(signum, frame):
exit()
def helptext(message):
helptext_string = f'''
jc: {message}
Usage: jc PARSER [OPTIONS]
Parsers:
--arp arp parser
--df df parser
--dig dig parser
--env env parser
--free free parser
--history history parser
--ifconfig iconfig parser
--iptables iptables parser
--jobs jobs parser
--ls ls parser
--lsblk lsblk parser
--lsmod lsmod parser
--lsof lsof parser
--mount mount parser
--netstat netstat parser
--ps ps parser
--route route parser
--uname uname parser
--uptime uptime parser
--w w parser
Options:
-p pretty print output
-q quiet - suppress warnings
-r raw JSON output
Example:
ls -al | jc --ls -p
'''
print(textwrap.dedent(helptext_string), file=sys.stderr)
def error_message(message):
error_string = f'''
jc: {message}
'''
print(textwrap.dedent(error_string), file=sys.stderr)
def compatibility(mod_name, compatible):
'''
compatible options: linux, darwin, cygwin, win32, aix, freebsd
'''
if sys.platform not in compatible:
mod = mod_name.split('.')[-1]
compat_list = ', '.join(compatible)
error_message(f'Warning - {mod} parser not compatible with your OS ({sys.platform}).\n Compatible platforms: {compat_list}')