summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2015-05-22 09:26:02 (GMT)
committerBaserock Gerrit <gerrit@baserock.org>2015-09-23 13:33:22 (GMT)
commitd6db02ba19525911671d35d1357e6e9f258ff573 (patch)
tree2e659529a0eec637741da373989de5a80704701a
parent235e95c3479f96b04d33edecc684f985bda50e53 (diff)
downloadtbdiff-d6db02ba19525911671d35d1357e6e9f258ff573.tar.gz
Add --json flag to list command
It's useful for morph (and potentially other programs) to be able to easily obtain the current list of systems without having to either duplicate the code in system-version-manager or parse its output. Change-Id: I2bf563920f6bd0372c82900257c4ba221caa7833
-rwxr-xr-xsystem-version-manager/system-version-manager17
1 files changed, 14 insertions, 3 deletions
diff --git a/system-version-manager/system-version-manager b/system-version-manager/system-version-manager
index 554e459..1cb53f8 100755
--- a/system-version-manager/system-version-manager
+++ b/system-version-manager/system-version-manager
@@ -52,6 +52,10 @@ class SystemVersionManager(object):
parser_list = subparsers.add_parser('list',
help='list show you a list of systems')
parser_list.set_defaults(action='list')
+ parser_list.add_argument(
+ '--json', action='store_true',
+ help=('output list of systems in json in the form: '
+ '{"factory": {"running": true, "default": true}}'))
# create the parser for the "deploy" command
parser_deploy= subparsers.add_parser('deploy',
@@ -196,8 +200,15 @@ class SystemVersionManager(object):
if os.path.islink(default_path):
self._atomic_symlink_update(default, default_path)
- def cmd_list(self):
- default_system = self._get_default()
+ def cmd_list(self, output_json):
+ default_system = self._get_default()
+ if output_json:
+ json.dump({system: {'default': system == self.default_system,
+ 'running': system == self.current_system}
+ for system in self._get_systems()},
+ sys.stdout)
+ return
+
for system in self._get_systems():
output = system
if system == self.current_system:
@@ -394,7 +405,7 @@ class SystemVersionManager(object):
try:
if action == "list":
- self.cmd_list()
+ self.cmd_list(output_json=args.json)
elif action == "deploy":
self.cmd_deploy(args.location)
elif action == "remove":