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

use entry_points instead of scripts

This commit is contained in:
Kelly Brazil
2019-10-16 15:03:34 -07:00
parent 72c69e7de5
commit e572b2edfa
2 changed files with 32 additions and 24 deletions

26
jc/jc
View File

@ -10,30 +10,34 @@ import jc.parsers.ifconfig
import jc.parsers.ls import jc.parsers.ls
import jc.parsers.netstat import jc.parsers.netstat
pretty = False def main():
data = sys.stdin.read() pretty = False
data = sys.stdin.read()
if len(sys.argv) < 2: if len(sys.argv) < 2:
print(f'\nError: {sys.argv[0]}\n Must specify parser. (e.g. --ls, --netstat, --ifconfig, etc.)') print(f'\nError: {sys.argv[0]}\n Must specify parser. (e.g. --ls, --netstat, --ifconfig, etc.)')
print(' Use -p to pretty print') print(' Use -p to pretty print')
print(f'\nExample: ls -al | {sys.argv[0]} --ls -p\n') print(f'\nExample: ls -al | {sys.argv[0]} --ls -p\n')
exit() exit()
arg = sys.argv[1] arg = sys.argv[1]
if len(sys.argv) > 2: if len(sys.argv) > 2:
if sys.argv[2] == '-p': if sys.argv[2] == '-p':
pretty = True pretty = True
if arg == '--ifconfig': if arg == '--ifconfig':
result = jc.parsers.ifconfig.parse(data) result = jc.parsers.ifconfig.parse(data)
elif arg == '--ls': elif arg == '--ls':
result = jc.parsers.ls.parse(data) result = jc.parsers.ls.parse(data)
elif arg == '--netstat': elif arg == '--netstat':
result = jc.parsers.netstat.parse(data) result = jc.parsers.netstat.parse(data)
# output resulting dictionary as json # output resulting dictionary as json
if pretty: if pretty:
print(json.dumps(result, indent=2)) print(json.dumps(result, indent=2))
else: else:
print(json.dumps(result)) print(json.dumps(result))
if __name__ == '__main__':
main()

View File

@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
setuptools.setup( setuptools.setup(
name='jc', name='jc',
version='0.1', version='0.1.1',
author='Kelly Brazil', author='Kelly Brazil',
description='This tool serializes the output of popular command line tools to structured JSON output.', description='This tool serializes the output of popular command line tools to structured JSON output.',
install_requires=[ install_requires=[
@ -17,7 +17,11 @@ setuptools.setup(
python_requires='~=3.4', python_requires='~=3.4',
url='https://github.com/kellyjonbrazil/jc', url='https://github.com/kellyjonbrazil/jc',
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
scripts=['jc/jc'], entry_points={
'console_scripts': [
'jc = jc/jc:main',
],
},
classifiers=[ classifiers=[
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License', 'License :: OSI Approved :: MIT License',