Files
trygo-py-cliclient/src/taiga_pycli/cli/hats.py
Deepak Mallubhotla 2dbd4a80a1
All checks were successful
Nix Tests / nix-test (nix-runner) (push) Successful in 7m39s
Python Tests / python-test (push) Successful in 8m12s
adding upload testing, etc.
2025-10-31 17:58:01 -05:00

67 lines
1.5 KiB
Python

import argparse
import logging
import typing
import taiga_pycli.config
import taiga_pycli.models
import taiga_pycli.service
_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("hat")
parser.add_argument(
"--name", type=str, help="The name of the hat to add", default=None
)
parser.add_argument(
"--description",
type=str,
help="The description of the hat to add",
default=None,
)
parser.set_defaults(func=run)
def run(cfg: taiga_pycli.config.Config, args):
# clnt = taiga_pycli.client.TryGoAPIClient("http://localhost:8080/")
backend = taiga_pycli.service.BackendService(cfg)
if args.name is not None:
if args.description is None:
_logger.error("Got a null description, exiting")
return
# both not None
backend.add_hat(args.name, args.description)
return
else:
_logger.debug("Not creating, just list")
if args.description is not None:
_logger.error("Provided a description without name")
response = backend.get_hats()
if response is None:
_logger.warning("none response here")
return
real_hats = []
for hat in response:
rh = taiga_pycli.models.Hat(
name=hat["name"],
description=hat["description"],
user_id=hat["user_id"],
)
real_hats.append(rh)
print(rh)
# _logger.info(response)
return