cli updates
This commit is contained in:
@@ -2,8 +2,9 @@ import argparse
|
||||
import pathlib
|
||||
import logging
|
||||
import trygo_py_cliclient.config
|
||||
import trygo_py_cliclient.client
|
||||
import trygo_py_cliclient.cli.common
|
||||
import trygo_py_cliclient.cli.register
|
||||
import trygo_py_cliclient.cli.login
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -17,11 +18,10 @@ def parse_args():
|
||||
"--config-file", type=str, help="config file location", default="config.toml"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--display-name", type=str, help="config file location", default=""
|
||||
)
|
||||
parser.add_argument("--email", type=str, help="config file location", default="")
|
||||
parser.add_argument("--password", type=str, help="config file location", default="")
|
||||
subparsers = parser.add_subparsers(dest="cmd", required=True)
|
||||
trygo_py_cliclient.cli.register.setup_parser(subparsers)
|
||||
trygo_py_cliclient.cli.login.setup_parser(subparsers)
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
@@ -35,8 +35,7 @@ def main():
|
||||
trygo_py_cliclient.cli.common.set_up_logging(
|
||||
config,
|
||||
)
|
||||
_logger.info(f"Got args {args=}")
|
||||
_logger.info(f"Loaded config {config=}")
|
||||
|
||||
clnt = trygo_py_cliclient.client.TryGoAPIClient("http://localhost:8080/")
|
||||
|
||||
response = clnt.register(args.email, args.password, args.display_name)
|
||||
args.func(args)
|
||||
|
||||
28
src/trygo_py_cliclient/cli/login.py
Normal file
28
src/trygo_py_cliclient/cli/login.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import argparse
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import trygo_py_cliclient.client
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
_SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
|
||||
else:
|
||||
_SubparserType = typing.Any
|
||||
|
||||
|
||||
def setup_parser(subparsers: _SubparserType) -> None:
|
||||
parser = subparsers.add_parser("login")
|
||||
|
||||
parser.add_argument("--email", type=str, help="config file location", default="")
|
||||
parser.add_argument("--password", type=str, help="config file location", default="")
|
||||
parser.set_defaults(func=run)
|
||||
|
||||
def run(args):
|
||||
|
||||
clnt = trygo_py_cliclient.client.TryGoAPIClient("http://localhost:8080/")
|
||||
|
||||
response = clnt.login(args.email, args.password)
|
||||
_logger.info(response)
|
||||
30
src/trygo_py_cliclient/cli/register.py
Normal file
30
src/trygo_py_cliclient/cli/register.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import argparse
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import trygo_py_cliclient.client
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
_SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
|
||||
else:
|
||||
_SubparserType = typing.Any
|
||||
|
||||
|
||||
def setup_parser(subparsers: _SubparserType) -> None:
|
||||
parser = subparsers.add_parser("register")
|
||||
|
||||
parser.add_argument(
|
||||
"--display-name", type=str, help="config file location", default=""
|
||||
)
|
||||
parser.add_argument("--email", type=str, help="config file location", default="")
|
||||
parser.add_argument("--password", type=str, help="config file location", default="")
|
||||
parser.set_defaults(func=run)
|
||||
|
||||
def run(args):
|
||||
|
||||
clnt = trygo_py_cliclient.client.TryGoAPIClient("http://localhost:8080/")
|
||||
response = clnt.register(args.email, args.password, args.display_name)
|
||||
_logger.info(response)
|
||||
@@ -158,7 +158,8 @@ class TryGoAPIClient:
|
||||
|
||||
_logger.info(f"Logging in user: {email}")
|
||||
|
||||
response_data = self._make_request("POST", "/auth/login", asdict(request_data))
|
||||
response_data = self._make_request("POST", "/auth/tokens", asdict(request_data))
|
||||
_logger.info(response_data)
|
||||
|
||||
# Parse response and create AuthResponse
|
||||
auth_response = AuthResponse(
|
||||
|
||||
Reference in New Issue
Block a user