Repository: unnonouno/jqp

Issue:
Formatted output
Currently jqp print json in one line. Formatted output is preferable.

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/8905620/badge)](https://coveralls.io/builds/8905620)

Coverage decreased (-1.4%) to 77.193% when pulling **c8444f7b1c104cf771d66488efd7a4ad611a9666 on indent** into **ed76ad8ae8f2b189c7dcfbdb2c3ec3668f403b35 on master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/8905634/badge)](https://coveralls.io/builds/8905634)

Coverage decreased (-1.4%) to 77.193% when pulling **e02710dccdf7aee7e46e993f8ac37a1583576544 on indent** into **ed76ad8ae8f2b189c7dcfbdb2c3ec3668f403b35 on master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/8905634/badge)](https://coveralls.io/builds/8905634)

Coverage decreased (-1.4%) to 77.193% when pulling **e02710dccdf7aee7e46e993f8ac37a1583576544 on indent** into **ed76ad8ae8f2b189c7dcfbdb2c3ec3668f403b35 on master**.


Patch:
diff --git a/README.rst b/README.rst
index a30b8d5..3308e34 100644
--- a/README.rst
+++ b/README.rst
@@ -58,7 +58,10 @@ Example
 ::
 
     % echo '{"name": "Taro", "age": 10}' | jqp '[j["name"], j["age"]]'
-    ["Taro", 10]
+    [
+        "Taro",
+        10
+    ]
 
 
 License
diff --git a/jqp/__init__.py b/jqp/__init__.py
index 6d3ed17..038953f 100644
--- a/jqp/__init__.py
+++ b/jqp/__init__.py
@@ -21,7 +21,7 @@ def _exit(error, return_code, message):
 
 
 def run(in_io, out_io, cmd, imports=[], sort_keys=False, raw_input_mode=False,
-        raw_output=False, join_output=False, ascii_output=True):
+        raw_output=False, join_output=False, ascii_output=True, indent=None):
     environment = {}
     for mod_name in imports:
         try:
@@ -55,7 +55,7 @@ def run(in_io, out_io, cmd, imports=[], sort_keys=False, raw_input_mode=False,
             try:
                 json.dump(
                     out, out_io, ensure_ascii=ascii_output,
-                    sort_keys=sort_keys)
+                    sort_keys=sort_keys, indent=indent)
             except Exception as e:
                 _exit(e, 3, 'Cannot dump result: line %d' % line_no)
 
@@ -72,6 +72,9 @@ def main():
     parser.add_argument(
         '--import', action='append', default=[],
         help='modules to import')
+    parser.add_argument(
+        '--indent', type=int, default=4,
+        help='use the given number of indent')
     parser.add_argument(
         '--sort-keys', '-S', action='store_true',
         help='sort keys in objects when the command print it')
@@ -93,4 +96,4 @@ def main():
     run(sys.stdin, sys.stdout, args.cmd, imports=getattr(args, 'import'),
         sort_keys=args.sort_keys, raw_input_mode=args.raw_input,
         raw_output=args.raw_output, join_output=args.join_output,
-        ascii_output=args.ascii_output)
+        ascii_output=args.ascii_output, indent=args.indent)


Test patch:
diff --git a/tests/run_test.py b/tests/run_test.py
index 50613ce..1f38058 100644
--- a/tests/run_test.py
+++ b/tests/run_test.py
@@ -61,6 +61,13 @@ class RunTest(unittest.TestCase):
         jqp.run(inputs, outputs, u'"\u3042"', ascii_output=True)
         self.assertEqual(outputs.getvalue(), '"\\u3042"\n')
 
+    def test_indent(self):
+        inputs = StringIO('''[1]
+''')
+        outputs = StringIO()
+        jqp.run(inputs, outputs, 'j', indent=4)
+        self.assertEqual(outputs.getvalue(), '[\n    1\n]\n')
+
     def test_parse_error(self):
         inputs = StringIO('invalid\n')
         outputs = StringIO()