Skip to content

'--metric' parser breaks on colon-namespaced metric keys — including the command's own --help example #286

Description

@nealab-ai

Summary

trcc theme create ... --metric 'metric_key:x,y[:color[:size]]' fails on any real metric key, because sensor keys are colon-namespaced (cpu:temp, gpu:0:temp, memory:percent) and the parser naively does a plain split(":").

Repro

The command's own --help text gives this example:

--metric 'cpu:temp:160,90:#ff8800:24'

Running it verbatim:

$ trcc theme create 87ad:70db test --bg bg.png --metric "cpu:temp:160,90:#ff8800:24"
Invalid value: Invalid coords in 'cpu:temp:160,90:#ff8800:24'; expected 'x,y' got 'temp'

The documented example fails against the tool's own parser.

Root cause

src/trcc/ui/cli/theme.py, _parse_metric_spec:

parts = spec.split(":")
...
metric_key, coords, *rest = parts

"cpu:temp:160,90:#ff8800:24".split(":")["cpu", "temp", "160,90", "#ff8800", "24"], so metric_key ends up as "cpu" and coords as "temp" — wrong for any key with an internal colon. Since every real sensor key from trcc system list-sensors (cpu:temp, gpu:0:temp, gpu:amd:0:temp, etc.) has at least one internal colon, this makes --metric unusable as documented for any actual sensor.

Local fix that worked for me

Changed to a bounded rsplit, which correctly isolates the trailing coords/color/size fields regardless of how many colons the metric key itself contains — as long as both color and size are always supplied (I always pass both, so this fully unblocks my use case):

parts = spec.rsplit(":", 3)

Caveat: this doesn't fully solve the general case — a 2-field spec (key:x,y, no color/size) with a colon-namespaced key is still ambiguous with a fixed-arity rsplit and would need smarter logic (e.g. find the segment containing a comma and treat everything before it, rejoined, as the key). I didn't attempt that since I always supply the full 4-field form.

Environment

trcc-linux 9.9.11 via pipx, Ubuntu 26.04 LTS, Python 3.14.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions