const std = @import("std"); const types = @import("lib/types.zig"); const CommandContext = types.CommandContext; const CommandStatus = types.CommandStatus; const OutputCapture = types.OutputCapture; pub const Help = struct { command: ?[]const u8 = null, pub fn eval(self: Help, ctx: CommandContext) !CommandStatus { if (self.command) |cmd| { return showCommandHelp(cmd, ctx); } else { return showGeneralHelp(ctx); } } }; fn showGeneralHelp(ctx: CommandContext) !CommandStatus { const help_text = \\DOSE - DOS-style Command Shell \\ \\Available commands: \\ \\File Operations: \\ COPY - Copy files \\ DIR - Display directory contents \\ TYPE - Display file contents \\ CD - Change directory \\ MD - Create directory \\ RD - Remove directory \\ REN - Rename files/directories \\ DEL - Delete files \\ MOVE - Move files/directories \\ \\System Commands: \\ ECHO - Display messages or control echo state \\ CLS - Clear screen \\ DATE - Display current date \\ TIME - Display current time \\ VER - Display version information \\ PATH - Display or set PATH environment variable \\ SORT - Sort input lines alphabetically \\ EXIT - Exit the shell \\ \\For help on a specific command, type: command /? \\Example: DIR /? \\ ; if (ctx.output_capture) |output| { try output.write(help_text); } else { try std.io.getStdOut().writeAll(help_text); } return CommandStatus{ .Code = 0 }; } fn showCommandHelp(command: []const u8, ctx: CommandContext) !CommandStatus { const cmd_upper = try std.ascii.allocUpperString(ctx.allocator, command); defer ctx.allocator.free(cmd_upper); const help_text = getCommandSpecificHelp(cmd_upper); if (ctx.output_capture) |output| { try output.write(help_text); } else { try std.io.getStdOut().writeAll(help_text); } return CommandStatus{ .Code = 0 }; } fn getCommandSpecificHelp(command: []const u8) []const u8 { if (std.mem.eql(u8, command, "DIR")) { return \\DIR - Display directory contents \\ \\Syntax: DIR [path] [/flags] \\ \\ path Directory path to list (default: current directory) \\ \\Flags: \\ /? Display this help message \\ /W Use wide list format (filenames only, multiple columns) \\ /B Use bare format (filenames only, one per line) \\ /S Display files in subdirectories as well \\ \\Example: DIR C:\ /W \\ ; } else if (std.mem.eql(u8, command, "COPY")) { return \\COPY - Copy files \\ \\Syntax: COPY source destination [/flags] \\ \\ source Source file or device \\ destination Destination file or device \\ \\Flags: \\ /? Display this help message \\ /Y Suppress prompting to confirm overwrite \\ \\Example: COPY file1.txt file2.txt \\ ; } else if (std.mem.eql(u8, command, "TYPE")) { return \\TYPE - Display file contents \\ \\Syntax: TYPE filename [/flags] \\ \\ filename File to display \\ \\Flags: \\ /? Display this help message \\ \\Example: TYPE readme.txt \\ ; } else if (std.mem.eql(u8, command, "CD") or std.mem.eql(u8, command, "CHDIR")) { return \\CD/CHDIR - Change directory \\ \\Syntax: CD [path] [/flags] \\ \\ path Directory to change to \\ \\Flags: \\ /? Display this help message \\ \\Example: CD C:\Windows \\ ; } else if (std.mem.eql(u8, command, "ECHO")) { return \\ECHO - Display messages or control echo state \\ \\Syntax: ECHO [message] [/flags] \\ ECHO ON|OFF \\ \\ message Text to display \\ \\Flags: \\ /? Display this help message \\ \\Example: ECHO Hello World \\ ; } else if (std.mem.eql(u8, command, "CLS")) { return \\CLS - Clear screen \\ \\Syntax: CLS [/flags] \\ \\Flags: \\ /? Display this help message \\ ; } else if (std.mem.eql(u8, command, "EXIT")) { return \\EXIT - Exit the shell \\ \\Syntax: EXIT [/flags] \\ \\Flags: \\ /? Display this help message \\ ; } else if (std.mem.eql(u8, command, "VER")) { return \\VER - Display version information \\ \\Syntax: VER [/flags] \\ \\Flags: \\ /? Display this help message \\ ; } else if (std.mem.eql(u8, command, "DATE")) { return \\DATE - Display current date \\ \\Syntax: DATE [/flags] \\ \\Flags: \\ /? Display this help message \\ ; } else if (std.mem.eql(u8, command, "TIME")) { return \\TIME - Display current time \\ \\Syntax: TIME [/flags] \\ \\Flags: \\ /? Display this help message \\ ; } else if (std.mem.eql(u8, command, "MD") or std.mem.eql(u8, command, "MKDIR")) { return \\MD/MKDIR - Create directory \\ \\Syntax: MD directory [/flags] \\ MKDIR directory [/flags] \\ \\ directory Directory path to create \\ \\Flags: \\ /? Display this help message \\ \\Example: MD C:\TEMP \\Note: Creates intermediate directories if needed \\ ; } else if (std.mem.eql(u8, command, "RD") or std.mem.eql(u8, command, "RMDIR")) { return \\RD/RMDIR - Remove directory \\ \\Syntax: RD directory [/flags] \\ RMDIR directory [/flags] \\ \\ directory Directory path to remove \\ \\Flags: \\ /? Display this help message \\ \\Example: RD C:\TEMP \\Note: Directory must be empty \\ ; } else if (std.mem.eql(u8, command, "REN") or std.mem.eql(u8, command, "RENAME")) { return \\REN/RENAME - Rename files or directories \\ \\Syntax: REN oldname newname [/flags] \\ RENAME oldname newname [/flags] \\ \\ oldname Current name of file or directory \\ newname New name for file or directory \\ \\Flags: \\ /? Display this help message \\ \\Example: REN file1.txt file2.txt \\ ; } else if (std.mem.eql(u8, command, "MOVE")) { return \\MOVE - Move files or directories \\ \\Syntax: MOVE source destination [/flags] \\ \\ source Source file or directory \\ destination Destination path \\ \\Flags: \\ /? Display this help message \\ \\Example: MOVE file1.txt C:\TEMP\file1.txt \\Note: MOVE command is currently a placeholder \\ ; } else if (std.mem.eql(u8, command, "PATH")) { return \\PATH - Display or set PATH environment variable \\ \\Syntax: PATH [/flags] \\ PATH newpath [/flags] \\ PATH=newpath \\ \\ newpath New PATH value to set \\ \\Flags: \\ /? Display this help message \\ \\Example: PATH C:\DOS;C:\UTILS \\Note: Without arguments, displays current PATH \\ ; } else if (std.mem.eql(u8, command, "SORT")) { return \\SORT - Sort input lines alphabetically \\ \\Syntax: SORT [/flags] \\ \\Flags: \\ /? Display this help message \\ \\Example: TYPE file.txt | SORT \\Note: Reads from standard input and sorts lines \\ ; } else if (std.mem.eql(u8, command, "DEL") or std.mem.eql(u8, command, "ERASE")) { return \\DEL/ERASE - Delete files \\ \\Syntax: DEL filename [/flags] \\ ERASE filename [/flags] \\ \\ filename File to delete \\ \\Flags: \\ /? Display this help message \\ \\Example: DEL temp.txt \\Note: Wildcard deletion not yet implemented \\ ; } else { return \\Unknown command. Type HELP for a list of commands. \\ ; } }