Skip to content

Commit 77c8b99

Browse files
committed
fix: -f format-flag consistency across implementations
- Zig rejected -f=NxM (only the other four accepted the '=' form); now strips an optional leading '=' in the short-flag handler. - Node rejected bare -f and consumed the next arg as the spec; now bare -f means default 8x10 grouping (matching Zig/Lua/C) and does not eat the input filename. New cross-impl test #5e (bare -f and -f=NxM both succeed).
1 parent b6f7ba2 commit 77c8b99

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

bin/printable-binary-node.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,9 @@ function parseArgs(argv) {
172172
} else if (arg === '-s' || arg === '--spaces') {
173173
spacesMode = true;
174174
} else if (arg === '-f' || arg === '--format') {
175-
if (i + 1 >= argv.length) {
176-
process.stderr.write('Error: --format requires a value like 75x1\n');
177-
process.exit(1);
178-
}
179-
formatSpec = argv[++i];
175+
// Bare -f: default grouping (8x10), like the other implementations. Do not
176+
// consume the next argument (it is the input file); use -f=NxM for a spec.
177+
formatSpec = '8x10';
180178
} else if (arg.startsWith('-f=')) {
181179
formatSpec = arg.slice(3);
182180
} else if (arg.startsWith('--format=')) {

src/zig/main.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ fn parseArgs(allocator: std.mem.Allocator, args: []const []const u8) !Options {
313313
'h' => opts.help_mode = true,
314314
'f' => {
315315
if (j + 1 < arg.len) {
316-
const parsed = parseFormatSpec(arg[j + 1 ..]) catch return error.InvalidFormat;
316+
// Accept both -f8x10 and -f=8x10 (strip an optional '=').
317+
const spec = arg[j + 1 ..];
318+
const spec_trimmed = if (spec.len > 0 and spec[0] == '=') spec[1..] else spec;
319+
const parsed = parseFormatSpec(spec_trimmed) catch return error.InvalidFormat;
317320
opts.format_mode = true;
318321
opts.format_group = parsed.group;
319322
opts.format_groups_per_line = parsed.per_line;

test/test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ else
264264
exit 1
265265
fi
266266
267+
# Test 5e: -f (bare, default grouping) and -f=NxM (attached spec) consistency
268+
echo -e "${BLUE}Test #5e: -f / -f=NxM format-flag consistency${NC}"
269+
rc1=0; printf 'AAAABBBB' | $SCRIPT -f >/dev/null 2>&1 || rc1=$?
270+
rc2=0; printf 'AAAABBBB' | $SCRIPT -f=2x2 >/dev/null 2>&1 || rc2=$?
271+
if [[ $rc1 -eq 0 && $rc2 -eq 0 ]]; then
272+
echo -e "${GREEN}PASS${NC}"
273+
else
274+
echo -e "${RED}FAIL${NC} (bare -f exit=$rc1, -f=2x2 exit=$rc2)"
275+
exit 1
276+
fi
277+
267278
# Test 6: Piped input
268279
echo -e "${BLUE}Test #6: Piped input${NC}"
269280
RESULT=$(echo -n "Test" | $SCRIPT | $SCRIPT -d)

0 commit comments

Comments
 (0)