Skip to content

cli: validate --location against ZONE_CHOICES (vendor the zone list + picker) #94

@LukasWodka

Description

@LukasWodka

Problem

EdgeDevice.location is CharField(choices=ZONE_CHOICES) (electricityMaps zones — https://api.electricitymap.org/v3/zones), so the backend serializer's ChoiceField rejects any value not in the list. The CLI doesn't validate --location / the location prompt against that list, so an invalid value (Germany, germany, eu-central-1, a typo) only fails at create time as a raw 400 — poor UX.

The location auto-detect (cli#93) always produces a valid zone (an ISO country code), so the happy path is fine. This is about the override / explicit---location path.

Proposal

Vendor ZONE_CHOICES into the CLI (the same way the ingestion schema is vendored via scripts/sync-schema.sh) and use it to:

  1. Validate --location and the interactive prompt input against the zone list — fail fast with a helpful message instead of a backend 400.
  2. Offer a picker in the interactive flow (the prompter.Select seam already exists), or at least suggest close matches on a miss (Germany → did you mean DE?).
  3. Keep cli#93's auto-detect feeding the default; validation just guards overrides + the flag.

Scope / notes

  • A sync script (e.g. scripts/sync-zones.sh) pulling ZONE_CHOICES keeps the CLI list in lock-step — same pattern as the schema sync. Decide source of truth: the backend's metaApi/models/zone_choices.py vs the upstream electricityMaps zones endpoint.
  • ~400 zones (countries + sub-zones like US-CAL-CISO, AU-NSW); a picker over that many needs search/filter (survey supports it).

Refs

RFC-0001 #830 · cli#92 (client commands) · cli#93 (location auto-detect) · backend metaApi/models/zone_choices.py. Found during the cli#93 build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions