Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented the CLI.

  • Loading branch information...
commit cea3d5d22bca748efdf09b4449df25e131659818 1 parent 71e986b
@zacharyvoase zacharyvoase authored
Showing with 23 additions and 2 deletions.
  1. +1 −1  setup.py
  2. +22 −1 src/jsonpipe.py
View
2  setup.py
@@ -19,6 +19,6 @@
package_dir={'': 'src'},
py_modules=['jsonpipe'],
entry_points={'console_scripts': ['jsonpipe = jsonpipe:main']},
- install_requires=['simplejson>=2.1.3'],
+ install_requires=['simplejson>=2.1.3', 'argparse>=1.2.1'],
test_suite='jsonpipe._get_tests',
)
View
23 src/jsonpipe.py
@@ -2,11 +2,22 @@
from __future__ import with_statement
import contextlib
+import os.path as p
import sys
+import argparse
import simplejson
+__all__ = ['JSONPiper', 'jsonpipe']
+
+# Read in the version from the VERSION file.
+version_filename = p.join(p.dirname(p.dirname(__file__)), 'VERSION')
+with open(version_filename) as version_file:
+ __version__ = version_file.read().strip()
+del version_filename, version_file
+
+
class JSONPiper(object):
u"""
@@ -242,5 +253,15 @@ def _get_tests():
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE))
+PARSER = argparse.ArgumentParser()
+PARSER.add_argument('-s', '--separator', metavar='SEP', default='/',
+ help="Set a custom path component separator (default: /)")
+PARSER.add_argument('-v', '--version', action='version',
+ version='jsonpipe v%s' % (__version__,))
+
+
def main():
- raise NotImplementedError
+ args = PARSER.parse_args()
+ json_obj = simplejson.load(sys.stdin,
+ object_pairs_hook=simplejson.OrderedDict)
+ JSONPiper(sys.stdout, pathsep=args.separator).write(json_obj)
Please sign in to comment.
Something went wrong with that request. Please try again.