Skip to content

Commit

Permalink
fix(cli): jina auth cli error (#5070)
Browse files Browse the repository at this point in the history
* fix(cli): jina auth cli error

* style: fix overload and cli autocomplete

Co-authored-by: Jina Dev Bot <dev-bot@jina.ai>
  • Loading branch information
hanxiao and jina-bot committed Aug 17, 2022
1 parent 840c221 commit b9bddd2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion extra-requirements.txt
Expand Up @@ -33,7 +33,7 @@ grpcio-health-checking>=1.46.0: core
pyyaml>=5.3.1: core
packaging>=20.0: core
docarray>=0.13.14: core
jina-hubble-sdk>=0.12.1: core
jina-hubble-sdk>=0.12.2: core
uvloop: perf,standard,devel
prometheus_client: perf,standard,devel
fastapi>=0.76.0: standard,devel
Expand Down
22 changes: 11 additions & 11 deletions jina/parsers/__init__.py
Expand Up @@ -238,6 +238,17 @@ def get_main_parser():
)
)

from hubble.parsers import get_main_parser as get_hubble_parser

get_hubble_parser(
sp.add_parser(
'auth',
description='Login to Jina AI with your GitHub/Google/Email account',
formatter_class=_chf,
help='Login to Jina AI',
)
)

set_help_parser(
sp.add_parser(
'help',
Expand Down Expand Up @@ -279,15 +290,4 @@ def get_main_parser():
)
)

from hubble.parsers import get_main_parser as get_hubble_parser

get_hubble_parser(
sp.add_parser(
'auth',
description='Login to Jina AI with your GitHub/Google/Email account',
formatter_class=_chf,
help='Login to Jina AI',
)
)

return parser
6 changes: 3 additions & 3 deletions jina/parsers/base.py
Expand Up @@ -14,10 +14,10 @@ def set_base_parser():

# create the top-level parser
urls = {
'Code': ('💻', 'https://github.com/jina-ai/jina'),
'Code': ('💻', 'https://oss.jina.ai'),
'Docs': ('📖', 'https://docs.jina.ai'),
'Help': ('💬', 'https://slack.jina.ai'),
'Hiring!': ('🙌', 'https://career.jina.ai'),
'Hiring!': ('🙌', 'https://jobs.jina.ai'),
}
url_str = '\n'.join(
f'- {v[0]:<10} {k:10.10}\t{colored(v[1], "cyan", attrs=["underline"])}'
Expand All @@ -26,7 +26,7 @@ def set_base_parser():

parser = argparse.ArgumentParser(
epilog=f'''
Jina (v{colored(__version__, "green")}) is the cloud-native neural search framework powered by deep learning.
Jina v{colored(__version__, "green")}: build cross-modal and multimodal applications on the cloud.
{url_str}
Expand Down
2 changes: 1 addition & 1 deletion jina/resources/extra-requirements.txt
Expand Up @@ -33,7 +33,7 @@ grpcio-health-checking>=1.46.0: core
pyyaml>=5.3.1: core
packaging>=20.0: core
docarray>=0.13.14: core
jina-hubble-sdk>=0.12.1: core
jina-hubble-sdk>=0.12.2: core
uvloop: perf,standard,devel
prometheus_client: perf,standard,devel
fastapi>=0.76.0: standard,devel
Expand Down
2 changes: 1 addition & 1 deletion jina_cli/__init__.py
Expand Up @@ -10,7 +10,7 @@ def _get_run_args(print_args: bool = True):

console = get_rich_console()

silent_print = {'help', 'hub', 'export'}
silent_print = {'help', 'hub', 'export', 'auth'}

parser = get_main_parser()
if len(sys.argv) > 1:
Expand Down
10 changes: 10 additions & 0 deletions jina_cli/api.py
Expand Up @@ -210,3 +210,13 @@ def help(args: 'Namespace'):
from jina_cli.lookup import lookup_and_print

lookup_and_print(args.query.lower())


def auth(args: 'Namespace'):
"""
Authenticate a user
:param args: arguments coming from the CLI.
"""
from hubble import api

getattr(api, args.cli2.replace('-', '_'))(args)
16 changes: 8 additions & 8 deletions jina_cli/autocomplete.py
Expand Up @@ -11,11 +11,11 @@
'new',
'gateway',
'hub',
'auth',
'help',
'pod',
'deployment',
'client',
'auth',
],
'completions': {
'executor': [
Expand Down Expand Up @@ -183,6 +183,13 @@
'--force',
],
'hub': ['--help', 'new', 'push', 'pull'],
'auth login': ['--help', '--force'],
'auth logout': ['--help'],
'auth token create': ['--help', '--expire'],
'auth token delete': ['--help'],
'auth token list': ['--help'],
'auth token': ['--help', 'create', 'delete', 'list'],
'auth': ['--help', 'login', 'logout', 'token'],
'help': ['--help'],
'pod': [
'--help',
Expand Down Expand Up @@ -306,12 +313,5 @@
'--return-responses',
'--protocol',
],
'auth login': ['--help', '--force'],
'auth logout': ['--help'],
'auth token create': ['--help', '--expire'],
'auth token delete': ['--help'],
'auth token list': ['--help'],
'auth token': ['--help', 'create', 'delete', 'list'],
'auth': ['--help', 'login', 'logout', 'token'],
},
}
2 changes: 1 addition & 1 deletion tests/unit/test_cli.py
Expand Up @@ -28,7 +28,7 @@ def test_help_lookup(cli, capsys):
assert cli in nkw2kw
lookup_and_print(cli)
captured = capsys.readouterr()
assert captured.out
assert 'Traceback (most recent call last)' not in captured.out


def test_main_cli():
Expand Down

0 comments on commit b9bddd2

Please sign in to comment.