Repository navigation
Accept bare t flag as transparency=150 - #1307
Merged
Merged
Conversation
The :help page and README document the short option t as a bare flag meaning transparency=150 (e.g. Oymyakon_tqp0.png), but the query parser rejected it with ERR007 because transparency is an integer option. Give t its documented value when it is used as a flag, so it parses in the query string and in PNG file names. An explicit transparency=N still wins.
chubin
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1263
Problem
:helpand the README documenttas a bare PNG flag meaningtransparency=150, and the README's PNG example uses it (Oymyakon_tqp0.png). The parser rejects it:transparencyis anintegeroption inoptions.yaml, andvalidateAndSetFlagreturnsErrValueRequiredfor every non-boolean option used as a flag. The query string form (/Oymyakon.png?t) fails with the sameERR007, because both paths go throughParseQueryString.Change
internal/query/parse.go: when a non-boolean option is used as a bare flag, look it up in a smallshortFlagValuestable (transparency: "150") instead of failing. If the same query also has an explicittransparency=N, the explicit value wins regardless of map iteration order.tis the only short option inoptions.yamlthat is not boolean, so no other flag changes behavior.internal/query/queryparser_test.go:TestTransparencyFlagcoversOymyakon_tqp0.png,Oymyakon_t.png,Oymyakon_t=200.png,Oymyakon_t_transparency=100.png(viaParseOptionsInFilename) and?t,?tqp0,?t&transparency=100,?transparency=100&t(viaParse, repeated 20 times because parameter order comes from a map).Testing
Run in the
golang:1.25image, withinternal/assets/embedpopulated the waybuild.sh assetsdoes:go test ./internal/query/...:TestTransparencyFlagfails onmasterwith theERR007above and passes with this change.TestWeatherUnitspasses on both. With the "explicit value wins" check removed, the test fails (3 of 3 runs).go test ./...: all packages pass.go vet ./internal/query/: no findings.gofmt -dshows nothing forparse.go; forqueryparser_test.goit shows only the existing import block.ParseQueryStringonmasterand this branch over 50,032 query strings (fixed edge cases plus random strings over the short-flag alphabet and separators), treating all error codes as one outcome. 1,355 inputs that were errors onmasternow parse; every one containst, and each result includestransparency=150or the explicit value. No input that parsed onmasterchanged. The other differences are only which error code is reported first (for exampletz:ERR007before,ERR003now).Not in this PR
The second point in this comment (the PNG has no alpha even when the value parses) is a separate problem. With this change,
Oymyakon_tqp0.pngno longer fails, but instrictQueryParser.Parsethe options from the file name are merged withmergo.Merge(opts, *filenameOpts), which only fills zero fields.ApplyParsedMaphas already setopts.Transparency = 255(andopts.Lang = "en") for the query-string side, so the file-name value is dropped. Checked withParse:TransparencyLang/Oymyakon_t=100.png(master and this branch)/Oymyakon_lang=fr.png(master and this branch)/Oymyakon_tqp0.png(this branch)/Oymyakon.png?t(this branch)So after
Parse,?tgivesTransparency150, while the file-name form parses but still reaches the renderer with 255 (opaque) until the merge is fixed. This PR fixes the error in the issue title; you may want to keep tracking the file-name transparency separately. I kept the merge out of this PR because fixing it changes the precedence of every file-name option.Related behavior this PR leaves unchanged:
transparency=0is turned into 255 (ApplyParsedMapandansitopngtreat 0 as unset), so fully transparent output is not reachable.ParseOptionsInFilenamelowercases the whole file name, so_T(no-terminal) in a file name becomest. Onmasterthat wasERR007; with this change it parses astransparency=150. The docstring exampleRome_0pq_lang=it_T.png->no-terminal=truewas already not what happens.Oymyakon_tqp0_t.png,Oymyakon_qq.png) is stillERR002, because each character is added to the query separately.