CLI: Add --resolve and --long to 'ara record list'

Re-order the columns to be consistent with the other list commands and
bring both --resolve and --long to it as well.

Change-Id: I31ffbbfb193c566f96704479d8d8e5a342efdd8a
This commit is contained in:
David Moreau Simard 2020-09-22 23:05:17 -04:00
parent cf84747717
commit 46a6123c1e
No known key found for this signature in database
GPG Key ID: 7D4729EC4E64E8B7

View File

@ -9,6 +9,7 @@ from cliff.command import Command
from cliff.lister import Lister
from cliff.show import ShowOne
import ara.cli.utils as cli_utils
from ara.cli.base import global_arguments
from ara.clients.utils import get_client
@ -35,6 +36,18 @@ class RecordList(Lister):
default=None,
help=("List records matching the specified key"),
)
parser.add_argument(
"--long",
action="store_true",
default=False,
help=("Don't truncate paths")
)
parser.add_argument(
"--resolve",
action="store_true",
default=os.environ.get("ARA_CLI_RESOLVE", False),
help=("Resolve IDs to identifiers (such as path or names). Defaults to ARA_CLI_RESOLVE or False")
)
parser.add_argument(
"--order",
metavar="<order>",
@ -75,8 +88,16 @@ class RecordList(Lister):
query["limit"] = args.limit
records = client.get("/api/v1/records", **query)
# TODO: Record list API should provide timestamps
columns = ("id", "playbook", "key", "type", "updated")
if args.resolve:
for record in records["results"]:
playbook = cli_utils.get_playbook(client, record["playbook"])
# Paths can easily take up too much width real estate
if not args.long:
record["playbook"] = "(%s) %s" % (playbook["id"], cli_utils.truncatepath(playbook["path"], 50))
else:
record["playbook"] = "(%s) %s" % (playbook["id"], playbook["path"])
columns = ("id", "key", "type", "playbook", "updated")
# fmt: off
return (
columns, (