Skip to content

Reject unsupported output extensions - #115

Merged
Psy-Fer merged 2 commits into
Psy-Fer:devfrom
eneskemalergin:fix/output-format-validation
Aug 5, 2026
Merged

Reject unsupported output extensions#115
Psy-Fer merged 2 commits into
Psy-Fer:devfrom
eneskemalergin:fix/output-format-validation

Conversation

@eneskemalergin

Copy link
Copy Markdown
Contributor

Hello there,

I wanted to open this PR because I realized that the output filename can currently conflict with the content Kuva writes. For example, -o plot.pgn, an output path without an extension, and even -o plot.PNG all succeed but contain SVG. The first two can hide a typo, while the last one looks like a PNG but isn't one.

I changed the CLI so .svg, .png, and .pdf are recognized case-insensitively. Other or missing extensions now return an error during argument parsing, before Kuva reads the input or renders anything, and no misleading output file is created.

What I changed:

  • added one shared output-format classifier rather than repeating the rule in each plot command;
  • used the same classifier for CLI validation and backend selection;
  • added regression tests for unknown and missing extensions, validation timing, and mixed-case SVG, PNG, and PDF output;
  • updated the related help text, README, CLI documentation, and changelog entry.

I kept the scope limited to CLI file output through -o/--output. SVG on stdout is unchanged, supported lowercase paths behave as before, and PNG/PDF still require their existing features. This does not add a --format flag or change the library backend APIs, terminal output, input handling, or rendering itself.

For testing, I first ran the new behaviour tests against the unchanged dev implementation and confirmed that the invalid paths were accepted and mixed-case PNG/PDF received SVG. On the updated branch, I ran:

  • the focused output classifier and CLI tests with both cli and cli,full features;
  • cargo ci-fmt;
  • cargo ci-clippy;
  • cargo ci-test, including the full CLI suite and doctests;
  • manual help, failure-side-effect, and --emit-code checks.

All of these passed. I could not run the mdBook build because mdbook is not installed in my local environment, but I reviewed the Markdown changes directly as the source.

I have a few questions where I would especially appreciate your preference:

  1. Does strict validation for unknown or missing extensions match the behaviour you want, or would you prefer to keep the implicit SVG fallback?
  2. I updated the directly related help, README, CLI documentation, and changelog so they match the new behaviour. If you prefer to keep documentation wording and style under your control, I am completely happy to reduce this PR to the code and tests.

Thank you for taking a look.

Type of change

  • New plot type
  • New feature / API addition
  • Bug fix
  • Documentation / assets only
  • Refactor / housekeeping

Checklist

Library (new plot type)

Not applicable — this does not add or change a plot type or public library API.

Tests

  • Added focused unit coverage for supported, mixed-case, missing, unsupported, trailing-dot, and non-Unicode extensions
  • Added CLI coverage for failure diagnostics, absence of output side effects, validation before input reading, and SVG/PNG/PDF content
  • Focused tests pass with both cli and cli,full
  • cargo ci-test — the complete suite passed, including 80 CLI tests and 186 doctests
  • cargo ci-fmt
  • cargo ci-clippy

CLI (if applicable)

  • Shared BaseArgs::output validation and help text updated
  • Shared backend selection uses the same format classifier
  • tests/cli_basic.rs updated with output and content verification
  • docs/src/cli/index.md updated with the new output contract
  • man/kuva.1 scope checked — flattened subcommand output options are not present, so regeneration produces no relevant change
  • Smoke-test scope checked — no command dispatch or rendering behaviour changed, so no new invocation was added

Documentation

  • README.md output guidance updated
  • docs/src/cli/index.md output guidance updated
  • CLI --help text updated and inspected
  • mdBook build — mdbook is not installed in my local environment; changed Markdown was reviewed as source

Visual inspection

Not applicable — this PR does not change plot rendering or layout. Mixed-case PNG and PDF output was validated structurally in the CLI tests.

Housekeeping

  • CHANGELOG.md entry added under ## [Unreleased]
  • Final diff and failure-side-effect checks reviewed

Enes K.

Comment thread CHANGELOG.md Outdated

### Fixed

- **CLI output extensions now select formats case-insensitively and reject unsupported paths:** `-o plot.PNG` and `-o plot.PdF` now use their intended backends, while unknown or missing extensions return an error instead of silently writing SVG content under a misleading file name.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably move this under a ### Changed heading rather than fixed, as it causes a break in expectation for someone writing to a output.dat and expecting svg or whatever.

@Psy-Fer Psy-Fer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, and I agree with strict enforcement. Doc changes are good too, just the one thing for the CHANGELOG moving it to a ### Changed subheading over fixed

@Psy-Fer

Psy-Fer commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Which I fixed doing the merge conflict :)

@Psy-Fer
Psy-Fer merged commit 8f8cd53 into Psy-Fer:dev Aug 5, 2026
5 checks passed
@eneskemalergin
eneskemalergin deleted the fix/output-format-validation branch August 7, 2026 16:15
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.

2 participants