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 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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue