add --json option for `dcos package repo list`
This commit is contained in:
tamarrow
2016-02-26 13:05:58 -08:00
6 changed files with 31 additions and 13 deletions

View File

@@ -18,7 +18,7 @@ Usage:
dcos package search [--json <query>]
dcos package repo add [--index=<index>] <repo-name> <repo-url>
dcos package repo remove (--repo-name=<repo-name> | --repo-url=<repo-url>)
dcos package repo list
dcos package repo list [--json]
dcos package uninstall [--cli | [--app --app-id=<app-id> --all]]
<package-name>

View File

@@ -55,8 +55,8 @@ def _cmds():
return [
cmds.Command(
hierarchy=['package', 'repo', 'list'],
arg_keys=[],
function=_list_response),
arg_keys=['--json'],
function=_list_repos),
cmds.Command(
hierarchy=['package', 'repo', 'add'],
@@ -138,9 +138,11 @@ def _info():
return 0
def _list_response():
def _list_repos(is_json):
"""List configured package repositories.
:param json_: output json if True
:type json_: bool
:returns: Process status
:rtype: int
"""
@@ -148,8 +150,12 @@ def _list_response():
package_manager = _get_package_manager()
repos = package_manager.get_repos()
if repos:
emitter.publish(repos)
if is_json:
return emitter.publish(repos)
elif repos.get("repositories"):
repos = ["{}: {}".format(repo.get("name"), repo.get("uri"))
for repo in repos.get("repositories")]
emitter.publish("\n".join(repos))
else:
msg = ("There are currently no repos configured. "
"Please use `dcos package repo add` to add a repo")

View File

@@ -18,7 +18,7 @@ Usage:
dcos package search [--json <query>]
dcos package repo add [--index=<index>] <repo-name> <repo-url>
dcos package repo remove (--repo-name=<repo-name> | --repo-url=<repo-url>)
dcos package repo list
dcos package repo list [--json]
dcos package uninstall [--cli | [--app --app-id=<app-id> --all]]
<package-name>

View File

@@ -0,0 +1,8 @@
{
"repositories": [
{
"name": "test4",
"uri": "https://github.com/mesosphere/universe/archive/cli-test-4.zip"
}
]
}

View File

@@ -59,6 +59,13 @@ test4: https://github.com/mesosphere/universe/archive/cli-test-4.zip
assert_command(['dcos', 'package', 'repo', 'list'], stdout=repo_list)
def test_repo_list_json():
repo_list = file_json(
'tests/data/package/json/test_repo_list.json')
assert_command(
['dcos', 'package', 'repo', 'list', '--json'], stdout=repo_list)
def test_repo_add():
repo = \
"https://github.com/mesosphere/universe/archive/cli-test-3.zip"

View File

@@ -158,14 +158,11 @@ class Cosmos():
def get_repos(self):
"""List locations of repos
:returns: the list of repos, in resolution order
:rtype: [str]
:returns: the list of repos, in resolution order or list
:rtype: dict
"""
response = self.cosmos_post("repository/list", params={})
repos = ["{}: {}".format(repo.get("name"), repo.get("uri"))
for repo in response.json().get("repositories")]
return "\n".join(repos)
return self.cosmos_post("repository/list", params={}).json()
def add_repo(self, name, package_repo, index):
"""Add package repo and update repo with new repo