bam cli: status now supports json output

This commit is contained in:
2014-11-28 11:50:01 +01:00
parent 3e846a8127
commit 4743d24b4e

View File

@@ -555,7 +555,7 @@ class bam_commands:
# if all goes well, rewrite sha1's # if all goes well, rewrite sha1's
@staticmethod @staticmethod
def status(paths): def status(paths, use_json=False):
# TODO(cam) multiple paths # TODO(cam) multiple paths
path = paths[0] path = paths[0]
del paths del paths
@@ -570,12 +570,24 @@ class bam_commands:
bam_session.status(session_rootdir, paths_add, paths_remove, paths_modified, paths_remap_subset_add) bam_session.status(session_rootdir, paths_add, paths_remove, paths_modified, paths_remap_subset_add)
for fn in sorted(paths_add): if use_json:
print(" A: %s" % fn) for fn in sorted(paths_add):
for fn in sorted(paths_modified): print(" A: %s" % fn)
print(" M: %s" % fn) for fn in sorted(paths_modified):
for fn in sorted(paths_remove): print(" M: %s" % fn)
print(" D: %s" % fn) for fn in sorted(paths_remove):
print(" D: %s" % fn)
else:
ret = []
for fn in sorted(paths_add):
ret.append(("A", fn))
for fn in sorted(paths_modified):
ret.append(("M", fn))
for fn in sorted(paths_remove):
ret.append(("D", fn))
import json
print(json.dumps(ret))
@staticmethod @staticmethod
def list_dir(paths, use_json=False): def list_dir(paths, use_json=False):
@@ -765,6 +777,9 @@ def create_argparse_status(subparsers):
dest="paths", nargs="*", dest="paths", nargs="*",
help="Path(s) to operate on", help="Path(s) to operate on",
) )
generic_argument_json(subparse)
subparse.set_defaults( subparse.set_defaults(
func=lambda args: func=lambda args:
bam_commands.status(args.paths or ["."]), bam_commands.status(args.paths or ["."]),