Skip to content

Commit db7a4ed

Browse files
Merge pull request #2011 from softlayer/jayasilan-issue1863
slcli search command help/abort message when no option provided
2 parents c810acf + c1e656f commit db7a4ed

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

SoftLayer/CLI/search.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
@click.argument('query', nargs=-1)
2525
@click.option('--types', is_flag=True, default=False, is_eager=True, help="Display searchable types.")
2626
@click.option('--advanced', is_flag=True, help="Calls the AdvancedSearh API.")
27+
@click.help_option('--help', '-h')
2728
@environment.pass_env
2829
def cli(env, query, types, advanced):
2930
"""Perform a query against the SoftLayer search database.
@@ -35,6 +36,21 @@ def cli(env, query, types, advanced):
3536
slcli search _objectType:SoftLayer_Virtual_Guest test.com
3637
slcli -vvv search _objectType:SoftLayer_Hardware hostname:testibm --advanced
3738
"""
39+
40+
# Before any Search operation
41+
def check_opt(list_opt=None):
42+
check = False
43+
for input_ in list_opt:
44+
if input_ is True:
45+
check = True
46+
break
47+
return check
48+
49+
list_opt = [query, types, advanced]
50+
51+
if not check_opt(list_opt):
52+
raise click.UsageError('Search query must be provided')
53+
3854
search = SearchManager(env.client)
3955
# query is in array, so we need to convert it to a normal string for the API
4056
query = " ".join(query)

tests/CLI/modules/search_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ def test_find(self):
1717
def test_find_advanced(self):
1818
result = self.run_command(['search', 'hardware', '--advanced'])
1919
self.assert_no_fail(result)
20+
21+
def test_no_options(self):
22+
result = self.run_command(['search'])
23+
self.assertEqual(result.exit_code, 2)

0 commit comments

Comments
 (0)