Skip to content

Commit

Permalink
Fix for flags with no -d prefix (inim-repl#104)
Browse files Browse the repository at this point in the history
* Added sample test to pass. Strip before checking piped commands

* Added fix from inim-repl#103 (comment)

* Updated README

Co-authored-by: Ryan Cotter <[email protected]>
  • Loading branch information
Tangdongle and Ryan Cotter authored Sep 6, 2020
1 parent 9c3ed8b commit 7a5fc60
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Edit lines using $EDITOR (Ctrl-X)
* Built in tools like ipython (cd(), ls(), pwd(), call()) enabled with --withTools
* When piped a file or some code, INim will execute that code and exit
* Extra compiler options can be specified by adding them as arguments inim with the -d flag (ie `inim -d:ssl -d:DEBUG`)
* Flags can turned on with `-d` by adding a `--` prefix to arguments (ie -d:--threads:on)

## Config
Config is saved and loaded from `configDir / inim`.
Expand Down
13 changes: 10 additions & 3 deletions src/inim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2018 Andrei Regiani

import os, osproc, strformat, strutils, terminal, sequtils,
times, strformat, parsecfg
times, strformat, parsecfg, sugar
import noise
from sequtils import filterIt

Expand Down Expand Up @@ -509,7 +509,7 @@ proc runCodeAndExit() =
## and echo the output

let codeToRun = stdin.readAll().strip()
let codeEndsInEcho = codeToRun.split({';', '\r', '\n'})[^1].startsWith("echo")
let codeEndsInEcho = codeToRun.split({';', '\r', '\n'})[^1].strip().startsWith("echo")

if codeEndsInEcho:
# If the code ends in an echo, just
Expand Down Expand Up @@ -551,8 +551,15 @@ proc main(nim = "nim", srcFile = "", showHeader = true,
## inim interpreter

initApp(nim, srcFile, showHeader)

if flags.len > 0:
app.flags = " -d:" & join(@flags, " -d:")
app.flags = flags.map(f => (
block:
if f.startsWith("--"):
return f
return fmt"-d:{f}"
)
).join(" ")

discard existsorCreateDir(getConfigDir())
let shouldCreateRc = not existsorCreateDir(rcFilePath.splitPath.head) or
Expand Down
3 changes: 3 additions & 0 deletions tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ suite "INim Test Suite":
test "Executes piped code with echo at end of block":
check execCmdEx("cat tests/test_piping_with_end_echo.nim | bin/inim").output.strip() == """TestVar"""

test "Verify flags with '--' prefix work":
check execCmdEx("""echo 'import threadpool; echo "SUCCESS"' | bin/inim --flag=--threads:on""").output.strip() == "SUCCESS"

0 comments on commit 7a5fc60

Please sign in to comment.