Skip to content

fix(cli): warn on duplicate global flags instead of silently last-wins (#243)#301

Open
RUNECTZ33 wants to merge 1 commit into
entrius:testfrom
RUNECTZ33:fix/243-warn-duplicate-globals
Open

fix(cli): warn on duplicate global flags instead of silently last-wins (#243)#301
RUNECTZ33 wants to merge 1 commit into
entrius:testfrom
RUNECTZ33:fix/243-warn-duplicate-globals

Conversation

@RUNECTZ33
Copy link
Copy Markdown

Summary

Closes #243.

alw view rates --netuid 7 --netuid 8 previously took 8 silently — no indication anywhere that 7 was discarded. parse_global_flags simply overwrote the dict entry on the second match.

Change

Track seen canonical keys in parse_global_flags. On a duplicate, keep the existing last-wins behavior (preserves any operator scripts that depended on it) but surface the override via stderr:

warning: duplicate global flag --netuid '8' overrides earlier --netuid '7'

Same handling for both --flag value and --flag=value forms.

Why warn rather than reject

Issue says "Warn or reject duplicate globals." I picked warn to:

  • Avoid breaking existing scripts that may rely on the override pattern (e.g., wrapper scripts that prepend defaults and then accept user overrides).
  • Stay parser-side conservative: rejection at parse time would terminate the whole command, often with no obvious recovery for the operator.
  • Make the silent failure visible immediately so a typo gets caught at the first run.

If maintainers prefer hard rejection instead, happy to flip — change is one branch in the same function.

Scope

allways/cli/swap_commands/helpers.py: +28 / -2. No new imports (sys already imported). Output goes via print(..., file=sys.stderr) so it doesn't pollute stdout for any tooling that pipes the CLI's normal output.

Test plan

  • AST parses cleanly: python3 -c "import ast; ast.parse(...)"
  • Logic verified manually:
    • argv=['alw', 'view', 'rates', '--netuid', '7', '--netuid', '8']overrides={'netuid': '8'} + stderr warning
    • argv=['alw', 'view', 'rates', '--netuid=7', '--netuid=8'] → same outcome
    • argv=['alw', 'view', 'rates', '--netuid', '7']overrides={'netuid': '7'} + no warning
  • Confirmed sys.stderr is the right channel — CLI's normal stdout output (rates table, etc.) stays intact for piping.

entrius#243)

Steps to reproduce: `alw view rates --netuid 7 --netuid 8` previously
took 8 silently with no indication anywhere that 7 was overridden.

Fix: track seen canonical keys in parse_global_flags; on a duplicate,
keep the existing last-wins behavior (preserves any operator scripts
that relied on it) but surface the override via stderr so a typo
becomes visible immediately rather than producing surprise downstream.

  warning: duplicate global flag --netuid '8' overrides earlier --netuid '7'

Closes entrius#243
@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: duplicate global --netuid / --network last-wins silently

1 participant