Compare commits

...

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
12e8b293bc [autofix.ci] apply automated fixes 2025-09-27 06:41:23 +00:00
Claude Bot
b3ba582625 feat: add -s as shorthand for --silent flag
Added -s as a short form alias for the --silent flag in both AutoCommand and RunCommand.
The --silent flag suppresses the printing of script commands when running package.json scripts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-27 06:38:49 +00:00
2 changed files with 99 additions and 2 deletions

View File

@@ -124,7 +124,7 @@ pub const auto_or_run_params = [_]ParamType{
pub const auto_only_params = [_]ParamType{
// clap.parseParam("--all") catch unreachable,
clap.parseParam("--silent Don't print the script command") catch unreachable,
clap.parseParam("-s, --silent Don't print the script command") catch unreachable,
clap.parseParam("--elide-lines <NUMBER> Number of lines of script output shown when using --filter (default: 10). Set to 0 to show all lines.") catch unreachable,
clap.parseParam("-v, --version Print version and exit") catch unreachable,
clap.parseParam("--revision Print version with revision and exit") catch unreachable,
@@ -132,7 +132,7 @@ pub const auto_only_params = [_]ParamType{
pub const auto_params = auto_only_params ++ runtime_params_ ++ transpiler_params_ ++ base_params_;
pub const run_only_params = [_]ParamType{
clap.parseParam("--silent Don't print the script command") catch unreachable,
clap.parseParam("-s, --silent Don't print the script command") catch unreachable,
clap.parseParam("--elide-lines <NUMBER> Number of lines of script output shown when using --filter (default: 10). Set to 0 to show all lines.") catch unreachable,
} ++ auto_or_run_params;
pub const run_params = run_only_params ++ runtime_params_ ++ transpiler_params_ ++ base_params_;

View File

@@ -0,0 +1,97 @@
import { spawnSync } from "bun";
import { describe, expect, it } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
describe("bun run --silent", () => {
it("-s works as shorthand for --silent", async () => {
const dir = tempDirWithFiles("silent-test", {
"package.json": JSON.stringify({
name: "test-silent",
scripts: {
test: "echo 'Hello from script'",
},
}),
});
// Test with --silent
const silentResult = spawnSync({
cmd: [bunExe(), "run", "--silent", "test"],
cwd: String(dir),
env: bunEnv,
});
// Test with -s
const shortResult = spawnSync({
cmd: [bunExe(), "run", "-s", "test"],
cwd: String(dir),
env: bunEnv,
});
// Both should have the same behavior - no script command printed
expect(silentResult.stdout.toString()).toBe("Hello from script\n");
expect(silentResult.stderr.toString()).toBe("");
expect(silentResult.exitCode).toBe(0);
expect(shortResult.stdout.toString()).toBe("Hello from script\n");
expect(shortResult.stderr.toString()).toBe("");
expect(shortResult.exitCode).toBe(0);
// Verify script output is the same for both
expect(shortResult.stdout.toString()).toBe(silentResult.stdout.toString());
});
it("-s silences script command output just like --silent", async () => {
const dir = tempDirWithFiles("silent-test-2", {
"package.json": JSON.stringify({
name: "test-silent-2",
scripts: {
greet: "echo 'Greetings'",
},
}),
});
// Test without any silent flag
const normalResult = spawnSync({
cmd: [bunExe(), "run", "greet"],
cwd: String(dir),
env: bunEnv,
});
// Test with -s
const shortResult = spawnSync({
cmd: [bunExe(), "run", "-s", "greet"],
cwd: String(dir),
env: bunEnv,
});
// Normal run should include the script command being printed
expect(normalResult.stderr.toString()).toContain("$ echo 'Greetings'");
expect(normalResult.stdout.toString()).toBe("Greetings\n");
// -s should suppress the command output
expect(shortResult.stderr.toString()).toBe("");
expect(shortResult.stdout.toString()).toBe("Greetings\n");
});
it("-s works with bun (AutoCommand)", async () => {
const dir = tempDirWithFiles("silent-auto", {
"package.json": JSON.stringify({
name: "test-auto",
scripts: {
start: "echo 'Starting app'",
},
}),
});
// Test with -s using AutoCommand (no explicit 'run')
const result = spawnSync({
cmd: [bunExe(), "-s", "start"],
cwd: String(dir),
env: bunEnv,
});
expect(result.stdout.toString()).toBe("Starting app\n");
expect(result.stderr.toString()).toBe("");
expect(result.exitCode).toBe(0);
});
});