Skip to content

Commit

Permalink
Merge pull request #111 from fox0430/addCmdOp
Browse files Browse the repository at this point in the history
[WIP] Add command line option. -v and --version
  • Loading branch information
fox0430 authored Nov 28, 2018
2 parents 649ced1 + dbb7a18 commit 2254ce9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/moe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import moepkg/editorview
import moepkg/gapbuffer
import moepkg/independentutils
import moepkg/unicodeext
import moepkg/cmdoption

when isMainModule:
let parsedList = parseCommandLineOption(commandLineParams())

startUi()

var status = initEditorStatus()
if commandLineParams().len >= 1:
status.filename = commandLineParams()[0].toRunes
if parsedList.filename != "":
status.filename = parsedList.filename.toRunes
if existsFile($(status.filename)):
try:
let textAndEncoding = openFile(status.filename)
Expand Down
21 changes: 21 additions & 0 deletions src/moepkg/cmdoption.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import parseopt, unicode

type
ComdParsedList* = tuple[
filename: string
]

proc parseCommandLineOption*(line: seq[string]): ComdParsedList =
result.filename = ""
var parsedLine = initOptParser(line)
for kind, key, val in parsedLine.getopt():
case kind:
of cmdArgument:
result.filename = key
of cmdShortOption, cmdLongOption:
case key:
of "v", "version":
echo "v0.0.35"
quit()
of cmdEnd:
assert(false)

0 comments on commit 2254ce9

Please sign in to comment.