refactor(cli): standardize dataset command format and remove redundant hash command

Standardized dataset.zig with proper doc comment format:
- Added /// doc comment with usage and subcommand descriptions
- Follows same format as other commands

Removed dataset_hash.zig:
- Hash computation is already automatic in 'dataset verify'
- Standalone 'ml dataset hash' command was redundant
- Users can use 'ml dataset verify <path>' to get hash

All tests pass.
This commit is contained in:
Jeremie Fraeys 2026-03-05 10:30:55 -05:00
parent b99cd6b0e3
commit 9b4bd1b103
No known key found for this signature in database

View file

@ -1,49 +0,0 @@
const std = @import("std");
const cli = @import("../../main.zig");
const hash_mod = @import("../../utils/hash.zig");
const io = @import("../../utils/io.zig");
pub const name = "dataset hash";
pub const description = "Hash a dataset directory using SHA256";
pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void {
// Parse arguments
if (args.len < 1) {
std.debug.print("Usage: ml dataset hash <path>\n", .{});
std.debug.print(" <path> Path to dataset directory\n", .{});
return;
}
const path = args[0];
// Hash the directory
io.printInfo("Hashing dataset at: {s}\n", .{path});
const hash = hash_mod.hashDirectoryToHex(allocator, path) catch |err| {
switch (err) {
error.PathTraversalAttempt => {
io.printError("Invalid path (path traversal detected): {s}\n", .{path});
},
error.NotAFile => {
io.printError("Not a regular file: {s}\n", .{path});
},
error.EmptyDirectory => {
io.printError("Directory is empty or contains no files: {s}\n", .{path});
},
error.MaxDepthExceeded => {
io.printError("Max directory depth exceeded (32): {s}\n", .{path});
},
error.OutOfMemory => {
io.printError("Out of memory\n", .{});
},
else => {
io.printError("Hash computation failed: {s}\n", .{@errorName(err)});
},
}
return err;
};
defer allocator.free(hash);
// Print result
io.printSuccess("Dataset hash: {s}\n", .{hash});
}