Skip to content

Commit

Permalink
add option --showHeader to allow skipping header, useful for using in…
Browse files Browse the repository at this point in the history
…im as cmd line tool
  • Loading branch information
timotheecour committed Jul 14, 2018
1 parent 3297137 commit cab5701
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import os, osproc, rdstdin, strutils, terminal, times, strformat
type App = ref object
nim: string
srcFile: string
showHeader: bool

var app:App

Expand All @@ -30,11 +31,6 @@ var
indentLevel = 0 # Current
buffer: File

proc newApp(nim: string, srcFile: string):App=
result.new()
result.nim=nim
result.srcFile=srcFile

proc getNimVersion*(): string =
let (output, status) = execCmdEx(fmt"{app.nim} --version")
doAssert status == 0, fmt"make sure {app.nim} is in PATH"
Expand Down Expand Up @@ -230,22 +226,27 @@ proc runForever() =
# Clean up
tempIndentCode = ""

proc main(nim="nim", srcFile = "") =
proc main(nim="nim", srcFile = "", showHeader = true) =
## inim interpreter
app = newApp(nim, srcFile)
app.new()
app.nim=nim
app.srcFile=srcFile
app.showHeader=showHeader

if srcFile.len>0:
doAssert(srcFile.fileExists, "cannot access " & srcFile)
doAssert(srcFile.splitFile.ext == ".nim")
let fileData = getFileData(srcFile)
init(fileData)
else:
init() # Clean init
welcomeScreen()
if app.showHeader: welcomeScreen()
runForever()

when isMainModule:
import cligen
dispatch(main, help = {
"nim": "path to nim compiler",
"srcFile": "nim script to run",
"showHeader": "show program info startup",
})

0 comments on commit cab5701

Please sign in to comment.