Repository navigation
fix(api): read --name value like --name=value (#68) - #73
Merged
Merged
Conversation
citty copies --json, --account and --raw to their one-letter aliases, and tg api passed every key it didn't know to Telegram. Every request carried r: false, and --json or --account calls also carried j or a. The same call therefore got a different replay fixture depending on how it was written. mtcute ignored these keys, so live calls were unaffected. The new e2e test records a fixture for the exact request with a stub client and checks that --username=myuser and --json find it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
citty read an undeclared --name without = as true and dropped the value as a stray positional. The form used in every docs example (tg api account.checkUsername --username myuser) therefore sent username: true and failed with TELEGRAM_ERROR, and only --name=value worked. A negative number such as --addOffset -10 was even read as short flags named after its digits, which put true in the request and junk keys next to it. tg api now pairs a --name that citty read as true with the argument after it, when that argument is a value or a negative number and comes after the method. Both forms then go through the same typing, so they build the same call. Keys that start with a digit are dropped. docs/api-design.md says which forms work and which names need --json. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The old argv had no --username before --, so citty never read the name as true and the test passed with the break removed. Naming the flag on both sides of -- leaves the break as the only thing that stops the pairing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
citty reads `--geoPoint.lat -1.5` as the short options 1, . and 5. The
`.` in the key filter exists for that `.` key, but the only full-CLI
case used `-10`, which gives digit keys only, so narrowing the filter
to digits left every test green while the request gained `'': { '':
true }`. The new case catches that.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The api subcommand gets --format/-f, --verbose/-v and --quiet/-q undeclared, so they went into the request as method arguments: adding -v to a call missed the replay fixture recorded without it, the same problem that dropping j, a and r fixed. With the new --name value pairing, --format pretty even sent format: 'pretty'. The docs already say a method argument with one of these names goes in --json, so tg now drops them like its own api options. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since tg api closes its client before it prints, -v and --verbose turn on mtcute's debug log, and its "client destroyed" lines go to stdout before the JSON. The -v and --verbose cases found their fixture and exited 0, but result.json was undefined, so they failed on every run. The cases now parse the envelope from where the JSON starts, and the replay runs unset MTCUTE_LOG_LEVEL and VERBOSE so a developer's shell can't add the log to the other cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The docs said tg reads its own options wherever they appear. Two placements fail: -f/--format between api and the method has its value taken as the method (INVALID_ARGS), and --account, --json and --raw before api are not tg api's options at all. The docs now say to put them after the method, list the other places that work, and name the method arguments (q, format) that have to go in --json. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
fix/api-space-flags-68
branch
from
October 22, 2026 13:02
dcc5b38 to
163ac91
Compare
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 #68
Problem
citty reads an undeclared
--namewithout=astrueand leaves the value as a stray positional. Sotg api account.checkUsername --username myuser, the form every docs example uses, sentusername: trueand failed withTELEGRAM_ERROR(exit 5). Only--username=myuserand--jsonworked. A negative number was worse:--addOffset -10becameaddOffset: trueplus junk keys named after the digits.Every request also carried
r: false, and--json/--accountcalls carriedj/a: citty copies those options to their one-letter aliases. tg's global options reach the api subcommand undeclared, so-v,--verbose,-f,--format,-qand--quietwent into the request too. mtcute ignores unknown keys, so live calls were fine, but the same call got a different replay fixture depending on how it was written.Fix
fix(api): keep the -j, -a and -r aliases out of the request: the aliases join the list of tg's own arguments that never reach Telegram.fix(api): read --name value like --name=value: the newspacedFlagValuesinsrc/utils/args.tspairs a--namethat citty read astruewith the argument after it. It does this only after the method, and only when that argument is a value or a negative number. The value then goes through the same typing as--name=value. Keys that start with a digit are dropped. Everything else parses as before:--name=value,--no-name,--account/-a,--json/-j,-r, a flag followed by another option or at the end (stilltrue), a value such as-hi(still needs=), and anything after--.fix(api): keep tg's global options out of the request:format/f,verbose/vandquiet/qjoin the same list. Without it, the new pairing would even sendformat: 'pretty'for--format pretty.docs/api-design.md("Argument Merging") now covers both forms, flags, negative numbers and values that start with-. It also lists the option names tg reads itself and keeps out of the request, and where they go: after the method (--json,--accountand--rawalso betweenapiand the method, the global options also beforeapi;-f/--formatbetweenapiand the method has its value taken as the method). A method argument with one of those names goes in--json(tg api contacts.search --json '{"q":"alice","limit":5}').tg api --helpmentions both forms.The README's
--username=myuserand the--username myuserexample in docs/cli-commands.md both work now.Behaviour change: a method argument that shares a name with a tg option now has to go in
--json.q(contacts.search,messages.search,messages.searchGlobal,channelParticipantsSearch) is the one that worked before:tg api contacts.search --q=alice --limit=5 --rawsentq, and now--q=…no longer reaches Telegram (and root's-qstill makes the failed call silent).format(account.getThemes) is also dropped, but--format=<theme format>always failed root's enum check.Replay fixtures: the alias keys (
j,a,r) and global options are gone, so replay fixture hashes fortg apicalls change. API fixtures recorded fortg apicalls need recording again. No fixtures are committed.Tests
src/__e2e__/api-args.e2e.test.ts: each test records a replay fixture for an exact request with a stub client, then runstg apiwithTELEGRAM_API_REPLAY=1. The fixture name is a hash of the request, so any extra key misses it.account.checkUsernamewith--username myuser,--username=myuserand--jsonall print the same success JSON, as do-v,--verbose,-f jsonand--format jsonnext to--username myuser(the envelope is read from where the JSON starts: under-vmtcute's debug log prints to stdout first, see follow-up 7; the replay runs unsetMTCUTE_LOG_LEVELandVERBOSE);-qand--quietexit 0 with no output.--username otherusermisses the fixture (exit 5,TELEGRAM_ERROR).contacts.getTopPeerswith--correspondentsfirst, last, and with--account 1/-a 1before or after the method.messages.getHistorywith--peer._,--addOffset -10,--limit 10and--jsonin both forms.contacts.getLocatedwith--geoPoint.lat -1.5in both forms: citty reads-1.5as the short options1,.and5, and none of them may reach the request.src/__tests__/args.test.ts:spacedFlagValueson citty's own parse of each argv. The--case names the flag on both sides of--, so it fails if the helper reads past--.--break fails the--unit test; narrowing the key filter to/^\d/fails the-1.5e2e case; without the global option names, all six newaccount.checkUsernamecases miss their fixture.account.checkUsernamecase failed with exit 5. After the first commit the space form still failed. After the second, everything passes.bun run checkandbun run test(1738 pass) are green locally;bun run test:e2ehas 271 pass, and its only failures are the network-bound "should try to fetch from API" cases incommands.e2e.test.ts, which time out the same way on main on this machine.Follow-ups (not in this PR)
--q/-qmake the call silent, and--format <x>with a value outside json/pretty/quiet fails citty's enum check with usage and exit 1. Placements that fail:tg api -f pretty <method>/tg api --format json <method>take the format value as the method (INVALID_ARGS), andtg -a 1 api …/tg -j '{}' api …fail with "Unknown command" because root doesn't declare-a/-jas value options. The docs now describe these.--peer @username(peer must be a TL object),contacts.getContactswithouthash,--peer.usernameobjects without_, and sendMessage withoutrandomId. They appear in docs/api-design.md, docs/cli-commands.md and the api.ts header comment.-xvalues are still silently ignored or misparsed. They could becomeINVALID_ARGS.--jsonisTELEGRAM_ERROR(exit 5) instead ofINVALID_ARGS.--hash 123) are written as 0 by mtcute's long writer, and parseInt loses precision above 2^53.--json '{"_":…}'can override the method.tg -v(orMTCUTE_LOG_LEVEL) sends mtcute's debug log to stdout (src/services/telegram.ts, log level 5), so the JSON output no longer parses.🤖 Generated with Claude Code