[Add] Implemented 'cat' command

This commit is contained in:
Ritchie Cunningham 2025-09-26 21:45:40 +01:00
parent bb17cf3473
commit a80764a70e
2 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,18 @@
-- /bin/cat - Concatenate files and print on stdout.
local filename = arg[1]
if not filename then
return "" -- No arguments, return nothing.
end
local target_node = current_dir.children[filename]
if not target_node then
return "cat: " .. filename .. ": No such file or directory."
end
if target_node.type == 1 then
return "cat: " .. filename .. ": Is a directory"
end
-- It's a file, return it's contents. :)
return target_node.content

View File

@ -12,7 +12,8 @@ LuaProcessor::LuaProcessor(void) {
"name", &vfs_node::name,
"type", &vfs_node::type,
"children", &vfs_node::children,
"read_only", &vfs_node::read_only); }
"read_only", &vfs_node::read_only,
"content", &vfs_node::content); }
LuaProcessor::~LuaProcessor(void) {}