Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Data Flow
Data Loading
osdu-cli
Commits
d1873062
Commit
d1873062
authored
Dec 08, 2021
by
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
Changes
9
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
README.rst
View file @
d1873062
...
...
@@ -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
------
...
...
setup.py
View file @
d1873062
...
...
@@ -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"
,
},
...
...
src/osducli/__init__.py
View file @
d1873062
...
...
@@ -12,4 +12,4 @@
""" OSDU command line environment"""
__VERSION__
=
"0.0.2
7
"
__VERSION__
=
"0.0.2
8
"
src/osducli/click_cli.py
View file @
d1873062
...
...
@@ -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"
,
"
qu
er
y
"
]:
if
param
.
name
in
[
"help"
,
"debug"
,
"config"
,
"output"
,
"
filt
er"
]:
common_opts
.
append
(
_rv
)
else
:
opts
.
append
(
_rv
)
...
...
@@ -169,8 +169,8 @@ def command_with_output(table_transformer=None):
callback
=
output_callback
,
)
@
click
.
option
(
"--
qu
er
y
"
,
help
=
"JMESPath
query
string. See http://jmespath.org/ for more information and examples."
,
"--
filt
er"
,
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
(
"
qu
er
y
"
)
kwargs
.
pop
(
"
filt
er"
)
result
=
func
(
*
args
,
**
kwargs
)
if
result
is
not
None
:
if
type
(
result
)
in
[
dict
,
list
]:
...
...
src/osducli/cliclient.py
View file @
d1873062
...
...
@@ -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
]
...
...
src/osducli/commands/search/id.py
View file @
d1873062
...
...
@@ -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
src/osducli/commands/search/kind.py
0 → 100644
View file @
d1873062
# 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
src/osducli/commands/search/query.py
View file @
d1873062
...
...
@@ -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
tests/test_help_text.py
View file @
d1873062
...
...
@@ -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
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment