Skip to content

Commit c5cd368

Browse files
committed
Add exit call for insufficient arguments in Zig main function
- Implemented std.process.exit(1) to terminate the program when fewer than 3 arguments are provided. - Ensured proper usage message is displayed before exiting.
1 parent c118e42 commit c5cd368

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

compiled_starters/zig/src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn main() !void {
1313

1414
if (args.len < 3) {
1515
std.debug.print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
16+
std.process.exit(1);
1617
}
1718

1819
const database_file_path: []const u8 = args[1];

solutions/zig/01-dr6/code/src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn main() !void {
1313

1414
if (args.len < 3) {
1515
std.debug.print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
16+
std.process.exit(1);
1617
}
1718

1819
const database_file_path: []const u8 = args[1];

solutions/zig/01-dr6/diff/src/main.zig.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@@ -1,36 +1,32 @@
1+
@@ -1,37 +1,33 @@
22
const std = @import("std");
33
var stdout_buffer: [1024]u8 = undefined;
44
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
@@ -14,6 +14,7 @@
1414

1515
if (args.len < 3) {
1616
std.debug.print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
17+
std.process.exit(1);
1718
}
1819

1920
const database_file_path: []const u8 = args[1];

starter_templates/zig/code/src/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn main() !void {
1313

1414
if (args.len < 3) {
1515
std.debug.print("Usage: {s} <database_file_path> <command>\n", .{args[0]});
16+
std.process.exit(1);
1617
}
1718

1819
const database_file_path: []const u8 = args[1];

0 commit comments

Comments
 (0)