Add rm utility and improve further
This commit is contained in:
parent
761eb0a5e6
commit
20f776b4bd
4 changed files with 36 additions and 7 deletions
23
cat.nim
23
cat.nim
|
|
@ -1,15 +1,26 @@
|
||||||
import cligen, os, streams
|
import cligen, os, streams
|
||||||
import common
|
import common
|
||||||
|
|
||||||
|
proc catFile(file:string) =
|
||||||
|
if not existsFile(file):
|
||||||
|
echo "cat: " & file & ": No such file or directory"
|
||||||
|
return
|
||||||
|
var s = newFileStream(file, fmRead)
|
||||||
|
while not s.atEnd:
|
||||||
|
write(stdout, s.readChar)
|
||||||
|
|
||||||
|
proc catStdin() =
|
||||||
|
var line = ""
|
||||||
|
while stdin.readLine(line):
|
||||||
|
echo line
|
||||||
|
|
||||||
proc main(files:seq[string]) =
|
proc main(files:seq[string]) =
|
||||||
|
if files.len == 0:
|
||||||
|
catStdin()
|
||||||
for file in files:
|
for file in files:
|
||||||
if file == "-":
|
if file == "-":
|
||||||
var line = ""
|
catStdin()
|
||||||
while stdin.readLine(line):
|
|
||||||
echo line
|
|
||||||
else:
|
else:
|
||||||
var s = newFileStream(file, fmRead)
|
catFile(file)
|
||||||
while not s.atEnd:
|
|
||||||
write(stdout, s.readChar)
|
|
||||||
|
|
||||||
dispatch(main, version=("version", nimbaseVersion))
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
|
|
|
||||||
2
head.nim
2
head.nim
|
|
@ -2,6 +2,8 @@ import cligen, os, streams
|
||||||
import common
|
import common
|
||||||
|
|
||||||
proc main(files:seq[string], lines=10, bytes=0) =
|
proc main(files:seq[string], lines=10, bytes=0) =
|
||||||
|
# if files.len == 0:
|
||||||
|
# files.add "-"
|
||||||
for file in files:
|
for file in files:
|
||||||
var s = newFileStream(file, fmRead)
|
var s = newFileStream(file, fmRead)
|
||||||
if bytes > 0:
|
if bytes > 0:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ requires "nim >= 0.19.0"
|
||||||
requires "cligen >= 0.9.19"
|
requires "cligen >= 0.9.19"
|
||||||
requires "stint >= 0.0.1"
|
requires "stint >= 0.0.1"
|
||||||
|
|
||||||
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "seq", "sleep", "sub", "tee", "true", "yes"]
|
bin = @["add", "cat", "cp", "div", "echo", "factor", "false", "head", "mkdir", "mul", "rm", "seq", "sleep", "sub", "tee", "true", "yes"]
|
||||||
|
|
||||||
binDir = "bin"
|
binDir = "bin"
|
||||||
|
|
|
||||||
16
rm.nim
Normal file
16
rm.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import cligen, os
|
||||||
|
import common
|
||||||
|
|
||||||
|
proc main(files:seq[string], force=false, recursive=false) =
|
||||||
|
for file in files:
|
||||||
|
if existsFile(file):
|
||||||
|
removeFile(file)
|
||||||
|
elif existsDir(file):
|
||||||
|
if recursive:
|
||||||
|
removeDir(file)
|
||||||
|
else:
|
||||||
|
echo "rm: cannot remove '" & file & "': Is a directory"
|
||||||
|
else:
|
||||||
|
echo "rm: cannot remove '" & file & "': No such file or directory"
|
||||||
|
|
||||||
|
dispatch(main, version=("version", nimbaseVersion))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue