Commit d1873062 authored by Mark Hewitt's avatar Mark Hewitt
Browse files

Merge branch 'feature/search-enhancements' into 'main'

search improvements

Closes #8

See merge request !10
parents 279ee188 eebf3c09
Pipeline #80883 passed with stages
in 2 minutes and 56 seconds
......@@ -28,6 +28,14 @@ For more information, specify the `-h` flag:
Change Log
==========
0.0.28
------
- search kind command
- search id supports limit
- search query supports a specific query
- global query option renamed to filter
0.0.27
------
......
......@@ -59,7 +59,7 @@ setup(
package_dir={"": "src"},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=["click", "jmespath", "osdu-sdk==0.0.8", "requests", "tabulate", "msal"],
install_requires=["click", "jmespath", "osdu-sdk==0.0.9", "requests", "tabulate", "msal"],
project_urls={
"Issue Tracker": "https://community.opengroup.org/osdu/platform/data-flow/data-loading/osdu-cli/-/issues",
},
......
......@@ -12,4 +12,4 @@
""" OSDU command line environment"""
__VERSION__ = "0.0.27"
__VERSION__ = "0.0.28"
......@@ -58,7 +58,7 @@ def _format_click_options(cmd: click.Command, ctx: Context, formatter: HelpForma
for param in cmd.get_params(ctx):
_rv = param.get_help_record(ctx)
if _rv is not None:
if param.name in ["help", "debug", "config", "output", "query"]:
if param.name in ["help", "debug", "config", "output", "filter"]:
common_opts.append(_rv)
else:
opts.append(_rv)
......@@ -169,8 +169,8 @@ def command_with_output(table_transformer=None):
callback=output_callback,
)
@click.option(
"--query",
help="JMESPath query string. See http://jmespath.org/ for more information and examples.",
"--filter",
help="JMESPath string for filtering output. See http://jmespath.org/ for more information and examples.",
callback=jmes_callback,
)
@functools.wraps(func)
......@@ -178,7 +178,7 @@ def command_with_output(table_transformer=None):
def func_wrapper(*args, **kwargs):
state = args[0]
kwargs.pop("output")
kwargs.pop("query")
kwargs.pop("filter")
result = func(*args, **kwargs)
if result is not None:
if type(result) in [dict, list]:
......
......@@ -66,7 +66,7 @@ def handle_cli_exceptions(function):
logger.error("Error %s", ex.message)
except ValueError as ex:
logger.error(MSG_JSON_DECODE_ERROR)
logger.debug(ex)
logger.error(ex)
except (NoOptionError, NoSectionError) as ex:
logger.warning(
"Configuration missing from config ('%s'). Run 'osdu config update'", ex.args[0]
......
......@@ -22,14 +22,26 @@ from osducli.cliclient import CliOsduClient, handle_cli_exceptions
# click entry point
@click.command(cls=CustomClickCommand)
@click.argument("id")
@click.option(
"-l",
"--limit",
"limit",
default=10,
show_default=True,
help="maximum number of records to return.",
)
@handle_cli_exceptions
@command_with_output("results[*]")
def _click_command(state: State, id: str): # noqa:W1 pylint: disable=invalid-name,redefined-builtin
def _click_command(
state: State, id: str, limit: int
): # noqa:W1 pylint: disable=invalid-name,redefined-builtin
"""Search for the specified id"""
return query(state, id)
return query(state, id, limit)
def query(state: State, id: str): # TO FIX later pylint: disable=invalid-name,redefined-builtin
def query(
state: State, id: str, limit: int
): # TO FIX later pylint: disable=invalid-name,redefined-builtin
"""Search for the specified id
Args:
......@@ -38,6 +50,6 @@ def query(state: State, id: str): # TO FIX later pylint: disable=invalid-name,r
connection = CliOsduClient(state.config)
search_client = SearchClient(connection)
json_response = search_client.query_by_id(id)
json_response = search_client.query_by_id(id, limit)
return json_response
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Search service query command"""
import click
from osdu.search import SearchClient
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import CliOsduClient, handle_cli_exceptions
# click entry point
@click.command(cls=CustomClickCommand)
@click.argument("kind")
@click.option(
"-l",
"--limit",
"limit",
default=10,
show_default=True,
help="maximum number of records to return.",
)
@handle_cli_exceptions
@command_with_output("results[*]")
def _click_command(
state: State, kind: str, limit: int
): # noqa:W1 pylint: disable=invalid-name,redefined-builtin
"""Search for items of the specified kind"""
return query(state, kind, limit)
def query(
state: State, kind: str, limit: int
): # TO FIX later pylint: disable=invalid-name,redefined-builtin
"""Search for the specified kind
Args:
state (State): Global state
"""
connection = CliOsduClient(state.config)
search_client = SearchClient(connection)
json_response = search_client.query_by_kind(kind, limit)
return json_response
......@@ -23,6 +23,7 @@ from osducli.cliclient import CliOsduClient, handle_cli_exceptions
@click.command(cls=CustomClickCommand)
@click.option("-k", "--kind", "kind", help="kind to search for")
@click.option("-id", "--id", "_id", help="id to search for")
@click.option("-q", "--query", "_query", help="custom search query")
@click.option(
"-l",
"--limit",
......@@ -33,13 +34,13 @@ from osducli.cliclient import CliOsduClient, handle_cli_exceptions
)
@handle_cli_exceptions
@command_with_output("results[*].{Id:id,Kind:kind,CreateTime:createTime}")
def _click_command(state: State, kind: str, _id: str, limit: int):
"""Query search service"""
return query(state, kind, _id, limit)
def _click_command(state: State, kind: str, _id: str, _query: str, limit: int):
"""Search using more advanced query terms"""
return query(state, kind, _id, _query, limit)
def query(
state: State, kind: str, id: str, limit: int
state: State, kind: str, id: str, custom_query: str, limit: int
): # pylint: disable=invalid-name,redefined-builtin
"""Query search service
......@@ -47,8 +48,8 @@ def query(
state (State): Global state
"""
connection = CliOsduClient(state.config)
search_client = SearchClient(connection)
json_response = search_client.query(kind, id, limit)
print(custom_query)
json_response = search_client.query(kind, id, custom_query, limit)
return json_response
......@@ -478,7 +478,7 @@ class HelpTextTests(unittest.TestCase):
self.validate_output(
"osdu search",
commands=("id", "info", "query"),
commands=("id", "info", "kind", "query"),
)
self.validate_output(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment