Skip to content

fix(cli): stop flag defaults from clobbering config-file values - #5

Open
fiskhest wants to merge 1 commit into
Townk:mainlinefrom
fiskhest:fix/cli-flag-config-overrides
Open

fix(cli): stop flag defaults from clobbering config-file values#5
fiskhest wants to merge 1 commit into
Townk:mainlinefrom
fiskhest:fix/cli-flag-config-overrides

Conversation

@fiskhest

Copy link
Copy Markdown

PR: fix(cli): stop flag defaults from clobbering config-file values

Base branch: mainline
Branch: fix/cli-flag-config-overrides
Commit: e8930a8 (patch: /tmp/opencode/skim-fix.patch)

Summary

When a config file is loaded with skim generate -c <file>, three CLI flags
unconditionally overwrite the corresponding config-file values even when the
flag is not passed on the command line:

  • -F/--use-system-fonts -> clobbers output.style.use_system_fonts
  • -N/--no-special-keys -> clobbers output.style.legend_tables.macros/tap_dances.show
  • -Y/--no-symbols -> clobbers output.style.legend_tables.symbols.show

Because the flags defaulted to False/True (not None), "flag absent" was
indistinguishable from "user explicitly passed the default", so
_get_config() had no way to know it should keep the config value.

Repro

# skimconfig.yaml
output:
  style:
    use_system_fonts: true
skim generate -c skimconfig.yaml -k keyboard.kbi -o layout/ --layer 0-3
grep -c @font-face layout/keymap-layer-1.svg   # -> 5 (fonts embedded anyway)

Expected: 0 (config honored without -F). Same for
legend_tables.*.show: false vs -N/-Y.

Fix

Make the three flags tri-state (None = not given) and only apply them in
_get_config() when not None.

  • src/skim/cli.py--use-system-fonts, -N/--no-special-keys,
    -Y/--no-symbols click options now default=None; generate() signature
    and the generate_keymap() call site pass None through for absent flags.
  • src/skim/data/cli.pyOutputFiles.use_system_fonts defaults to None.
  • src/skim/application/keymap_generator.py_get_config() only applies
    use_system_fonts, show_special_keys_legend, and show_symbol_legend
    when the argument is not None; generate_keymap() widens the two legend
    params to bool | None.
  • src/skim/application/exporter/__init__.pysave_drawings() now takes
    the resolved use_system_fonts value (previously it re-read the raw CLI
    value, so cairo/PNG export would ignore the config).

Tests

  • tests/unit/application/test_keymap_generator.py — precedence matrix for
    _get_config(): config value preserved when flag absent; explicit
    True/False still wins.
  • tests/unit/test_cli.py — absent flags propagate as None; -F, -N,
    -Y propagate their values.
  • tests/unit/data/test_cli.pyOutputFiles.use_system_fonts default is
    now None.

Verification

  • uv run pytest tests/unit — 1410 passed, 1 skipped (81.61% coverage, meets 80%)
  • uv run ruff check src tests — clean
  • uv run ruff format --check src tests — clean
  • uv run basedpyright src — 0 errors
  • Manual:
    • config use_system_fonts: true, no flag -> @font-face count 0
    • -F flag -> @font-face count 0
    • no config, no flag -> @font-face count 5 (defaults unchanged)

The -F/--use-system-fonts, -N/--no-special-keys, and -Y/--no-symbols
flags defaulted to False/True (not None), so _get_config() could not
distinguish 'flag absent' from 'flag explicitly given' and always
overwrote the values loaded from the config file. As a result a config
like output.style.use_system_fonts: true was silently ignored unless
-F was passed on the command line.

Make the flags tri-state (None = not given):
- cli.py: click options default to None; generate() and the
  generate_keymap() call site pass None through for absent flags
- data/cli.py: OutputFiles.use_system_fonts defaults to None
- keymap_generator.py: _get_config() only applies use_system_fonts,
  show_special_keys_legend, and show_symbol_legend when not None;
  generate_keymap() widens the two legend params to bool | None
- exporter: save_drawings() takes the resolved use_system_fonts value
  so cairo/PNG export honors the config too

Adds unit tests for the _get_config() precedence matrix and CLI flag
propagation (tests/unit/application/test_keymap_generator.py,
tests/unit/test_cli.py, tests/unit/data/test_cli.py).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant