|
| 1 | +import argparse |
| 2 | +import json |
| 3 | + |
| 4 | +from enapter import cli, http |
| 5 | + |
| 6 | +from .site_location import parse_site_location |
| 7 | + |
| 8 | + |
| 9 | +class SiteUpdateCommand(cli.Command): |
| 10 | + |
| 11 | + @staticmethod |
| 12 | + def register(parent: cli.Subparsers) -> None: |
| 13 | + parser = parent.add_parser( |
| 14 | + "update", formatter_class=argparse.ArgumentDefaultsHelpFormatter |
| 15 | + ) |
| 16 | + parser.add_argument("id", nargs="?", type=str, help="ID of the site to update") |
| 17 | + parser.add_argument("-n", "--name", type=str, help="New name for the site") |
| 18 | + parser.add_argument( |
| 19 | + "-t", "--timezone", type=str, help="New timezone for the site" |
| 20 | + ) |
| 21 | + parser.add_argument( |
| 22 | + "-l", |
| 23 | + "--location", |
| 24 | + type=parse_site_location, |
| 25 | + help="New location for the site", |
| 26 | + ) |
| 27 | + |
| 28 | + @staticmethod |
| 29 | + async def run(args: argparse.Namespace) -> None: |
| 30 | + async with http.api.Client(http.api.Config.from_env()) as client: |
| 31 | + site = await client.sites.update( |
| 32 | + site_id=args.id, |
| 33 | + name=args.name, |
| 34 | + timezone=args.timezone, |
| 35 | + location=( |
| 36 | + http.api.sites.Location( |
| 37 | + name=args.location[0], |
| 38 | + latitude=args.location[1], |
| 39 | + longitude=args.location[2], |
| 40 | + ) |
| 41 | + if args.location is not None |
| 42 | + else None |
| 43 | + ), |
| 44 | + ) |
| 45 | + print(json.dumps(site.to_dto())) |
0 commit comments