From 34cc82c1ed2c47c752aeb514df2efa157f9087c4 Mon Sep 17 00:00:00 2001 From: jinhyuk9714 Date: Tue, 19 May 2026 20:54:08 +0900 Subject: [PATCH] fix(cli): parse inline optional short flag values --- src/clap/streaming.rs | 26 ++++++++++++++++++++++++-- test/cli/bun.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/clap/streaming.rs b/src/clap/streaming.rs index b13c78c22832..5d4377fda778 100644 --- a/src/clap/streaming.rs +++ b/src/clap/streaming.rs @@ -252,6 +252,12 @@ where if next_is_eql && param.takes_value == clap::Values::None { return Err(self.err(arg, Some(short), None, ArgError::DoesntTakeValue)); } + if next_is_eql { + return Ok(Some(Arg { + param, + value: Some(&arg[next_index + 1..]), + })); + } return Ok(Some(Arg { param, value: None })); } @@ -416,7 +422,7 @@ mod tests { #[test] fn short_params() { - let params: [clap::Param; 4] = [ + let params: [clap::Param; 5] = [ clap::Param { id: 0, names: clap::Names::short(b'a'), @@ -439,17 +445,25 @@ mod tests { takes_value: clap::Values::Many, ..Default::default() }, + clap::Param { + id: 4, + names: clap::Names::short(b'e'), + takes_value: clap::Values::OneOptional, + ..Default::default() + }, ]; let a = ¶ms[0]; let b = ¶ms[1]; let c = ¶ms[2]; let d = ¶ms[3]; + let e = ¶ms[4]; test_no_err( ¶ms, &[ - b"-a", b"-b", b"-ab", b"-ba", b"-c", b"0", b"-c=0", b"-ac", b"0", b"-ac=0", b"-d=0", + b"-a", b"-b", b"-ab", b"-ba", b"-c", b"0", b"-c=0", b"-ac", b"0", b"-ac=0", + b"-d=0", b"-e=1", b"-e", ], &[ Arg { @@ -504,6 +518,14 @@ mod tests { param: d, value: Some(b"0"), }, + Arg { + param: e, + value: Some(b"1"), + }, + Arg { + param: e, + value: None, + }, ], ); } diff --git a/test/cli/bun.test.ts b/test/cli/bun.test.ts index 7e974a6e692c..7f897f6e828b 100644 --- a/test/cli/bun.test.ts +++ b/test/cli/bun.test.ts @@ -142,5 +142,29 @@ describe("bun", () => { fs.unlinkSync(path); } }); + + test("-c=path loads bunfig like --config=path, issue #21431", () => { + using dir = tempDir("config-short-flag-value", { + "custom.toml": `preload = ["./preload.ts"]`, + "preload.ts": `globalThis.__bunConfigLoaded = true;`, + "index.ts": `console.log(globalThis.__bunConfigLoaded === true ? "loaded" : "missing");`, + }); + + for (const args of [ + ["-c=custom.toml", "index.ts"], + ["-c=custom.toml", "run", "index.ts"], + ["run", "-c=custom.toml", "index.ts"], + ]) { + const { stdout, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), ...args], + cwd: String(dir), + env: bunEnv, + stderr: "inherit", + }); + + expect(stdout.toString()).toBe("loaded\n"); + expect(exitCode).toBe(0); + } + }); }); });