[Add] Implemented 'cat' command
This commit is contained in:
parent
bb17cf3473
commit
a80764a70e
18
assets/scripts/bin/cat.lua
Normal file
18
assets/scripts/bin/cat.lua
Normal 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
|
||||||
@ -12,7 +12,8 @@ LuaProcessor::LuaProcessor(void) {
|
|||||||
"name", &vfs_node::name,
|
"name", &vfs_node::name,
|
||||||
"type", &vfs_node::type,
|
"type", &vfs_node::type,
|
||||||
"children", &vfs_node::children,
|
"children", &vfs_node::children,
|
||||||
"read_only", &vfs_node::read_only); }
|
"read_only", &vfs_node::read_only,
|
||||||
|
"content", &vfs_node::content); }
|
||||||
|
|
||||||
LuaProcessor::~LuaProcessor(void) {}
|
LuaProcessor::~LuaProcessor(void) {}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user