OctOS: Add touch, rm, and cp commands

Documented in `commands.md`
master
octacian 2017-03-28 17:09:53 -07:00
parent 5d59142b10
commit b84a250c25
7 changed files with 75 additions and 1 deletions

View File

@ -8,4 +8,13 @@ Shows help about the command specified or all commands if `all` is specified.
Runs Lua code from the command line under the secure environment.
#### `echo [text]`
Print text to the command line.
Print text to the command line.
#### `touch [path]`
Create new file.
#### `rm [path]`
Remove file.
#### `cp [old path] [new path]`
Make a copy of a file.

4
octos/bin/cp Normal file
View File

@ -0,0 +1,4 @@
name = cp
description = Copy file
params = [original path] [copy path]
exec = os/exec/cp.lua

4
octos/bin/rm Normal file
View File

@ -0,0 +1,4 @@
name = rm
description = Remove file
params = [path]
exec = os/exec/rm.lua

4
octos/bin/touch Normal file
View File

@ -0,0 +1,4 @@
name = touch
description = Create a file
params = [path]
exec = os/exec/touch.lua

21
octos/exec/cp.lua Normal file
View File

@ -0,0 +1,21 @@
local path = ...
local old = path[1]
local new = path[2]
if old and new then
if fs.exists(old) then
if not fs.exists(new) then
if fs.copy(old, new) then
print("Copied "..old.." to "..new)
else
print(old.." is a directory")
end
else
print(new.." already exists")
end
else
print(old.." does not exist")
end
else
print("Must specify original and new path (see help cp)")
end

16
octos/exec/rm.lua Normal file
View File

@ -0,0 +1,16 @@
local path = ...
path = path[1]
if path then
if fs.exists(path) then
if fs.remove(path) then
print("Removed file "..path)
else
print(path.." is a directory")
end
else
print(path.." does not exist")
end
else
print("Must specify path (see help rm)")
end

16
octos/exec/touch.lua Normal file
View File

@ -0,0 +1,16 @@
local path = ...
path = path[1]
if path then
if not fs.exists(path) then
if fs.create(path) then
print("Created file "..path)
else
print("Could not create file "..path)
end
else
print(path.." already exists")
end
else
print("Must specify path (see help touch)")
end