diff options
Diffstat (limited to 'src/cmd/help.zig')
-rw-r--r-- | src/cmd/help.zig | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/src/cmd/help.zig b/src/cmd/help.zig new file mode 100644 index 0000000..e5cdad3 --- /dev/null +++ b/src/cmd/help.zig @@ -0,0 +1,208 @@ +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 { + return + \\Unknown command. Type HELP for a list of commands. + \\ + ; + } +} |