Merge "Add optional fields for source to query cli"
This commit is contained in:
@@ -53,10 +53,15 @@ class SearchResource(lister.Lister):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--source",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Whether to display the source details, defaults to false. "
|
||||
"You can specify --max-width to make the output look better."
|
||||
nargs='?',
|
||||
const='all_sources',
|
||||
metavar="[<field>,...]",
|
||||
help="Whether to display the json source. If not specified, "
|
||||
"it will not be displayed. If specified with no argument, "
|
||||
"the full source will be displayed. Otherwise, specify the "
|
||||
"fields combined with ',' to return the fields you want."
|
||||
"It is recommended that you use the --max-width argument "
|
||||
"with this option."
|
||||
)
|
||||
return parser
|
||||
|
||||
@@ -72,8 +77,11 @@ class SearchResource(lister.Lister):
|
||||
"type": parsed_args.type,
|
||||
"all_projects": parsed_args.all_projects
|
||||
}
|
||||
if parsed_args.source:
|
||||
source = parsed_args.source
|
||||
if source:
|
||||
columns = ("ID", "Score", "Type", "Source")
|
||||
if source != "all_sources":
|
||||
params["_source"] = source.split(",")
|
||||
else:
|
||||
columns = ("ID", "Name", "Score", "Type", "Updated")
|
||||
# Only return the required fields when source not specified.
|
||||
|
@@ -39,8 +39,12 @@ class TestSearchResource(TestSearch):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
details = False
|
||||
if assertArgs.get('source'):
|
||||
details = assertArgs.pop('source')
|
||||
if assertArgs.get("source"):
|
||||
details = True
|
||||
if assertArgs.get("source") == "all_resources":
|
||||
assertArgs.pop("source")
|
||||
else:
|
||||
assertArgs["_source"] = assertArgs.pop("source")
|
||||
self.search_client.search.assert_called_with(**assertArgs)
|
||||
|
||||
if details:
|
||||
@@ -88,4 +92,10 @@ class TestSearchResource(TestSearch):
|
||||
def test_list_source(self):
|
||||
self._test_search(["name: fake", "--source"],
|
||||
query={"query_string": {"query": "name: fake"}},
|
||||
all_projects=False, source=True, type=None)
|
||||
all_projects=False, source="all_resources",
|
||||
type=None)
|
||||
|
||||
def test_list_optional_source(self):
|
||||
self._test_search(["name: fake", "--source", "f1,f2"],
|
||||
query={"query_string": {"query": "name: fake"}},
|
||||
all_projects=False, source=["f1", "f2"], type=None)
|
||||
|
Reference in New Issue
Block a user