Add rm utility and improve further

This commit is contained in:
joachimschmidt557 2019-03-27 11:49:48 +01:00
parent 761eb0a5e6
commit 20f776b4bd
4 changed files with 36 additions and 7 deletions

23
cat.nim
View file

@ -1,15 +1,26 @@
import cligen, os, streams
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]) =
if files.len == 0:
catStdin()
for file in files:
if file == "-":
var line = ""
while stdin.readLine(line):
echo line
catStdin()
else:
var s = newFileStream(file, fmRead)
while not s.atEnd:
write(stdout, s.readChar)
catFile(file)
dispatch(main, version=("version", nimbaseVersion))