|
|
@ -1,4 +1,4 @@
|
|
|
|
import cliutils, linenoise, os, osproc, sequtils, strutils
|
|
|
|
import cliutils, docopt, linenoise, os, osproc, sequtils, strutils
|
|
|
|
|
|
|
|
|
|
|
|
proc writeOutput(msg, errMsg: TaintedString, cmd: string): void =
|
|
|
|
proc writeOutput(msg, errMsg: TaintedString, cmd: string): void =
|
|
|
|
if not msg.isEmptyOrWhitespace: stdout.writeLine(msg)
|
|
|
|
if not msg.isEmptyOrWhitespace: stdout.writeLine(msg)
|
|
|
@ -6,15 +6,18 @@ proc writeOutput(msg, errMsg: TaintedString, cmd: string): void =
|
|
|
|
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
when isMainModule:
|
|
|
|
|
|
|
|
|
|
|
|
if paramCount() == 0:
|
|
|
|
let usage = """
|
|
|
|
stderr.writeLine "cmd_shell: no arguments"
|
|
|
|
Usage:
|
|
|
|
quit(QuitFailure)
|
|
|
|
cmd_shell [--prepend-args] <cmd> [-- <args>...]
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Parse arguments
|
|
|
|
|
|
|
|
let args = docopt(usage, version = "1.1.0")
|
|
|
|
|
|
|
|
|
|
|
|
let cmdPrompt = paramStr(1)
|
|
|
|
let cmdPrompt = $args["<cmd>"]
|
|
|
|
let cmd = '"' & cmdPrompt & '"'
|
|
|
|
let cmd = '"' & cmdPrompt & '"'
|
|
|
|
|
|
|
|
|
|
|
|
let args =
|
|
|
|
let argsForCmd =
|
|
|
|
if paramCount() > 1: commandLineParams()[1..^1].mapIt("'" & $it & "'").join(" ")
|
|
|
|
if args["<args>"]: @(args["<args>"]).mapIt("'" & $it & "'").join(" ")
|
|
|
|
else: ""
|
|
|
|
else: ""
|
|
|
|
|
|
|
|
|
|
|
|
discard historySetMaxLen(
|
|
|
|
discard historySetMaxLen(
|
|
|
@ -24,6 +27,9 @@ when isMainModule:
|
|
|
|
var line = readLine(cmdPrompt & "> ")
|
|
|
|
var line = readLine(cmdPrompt & "> ")
|
|
|
|
|
|
|
|
|
|
|
|
while line != nil:
|
|
|
|
while line != nil:
|
|
|
|
discard exec(cmd & " " & args & $line, "", [], nil, {poUsePath, poEvalCommand}, writeOutput)
|
|
|
|
if args["--prepend-args"]:
|
|
|
|
|
|
|
|
discard exec(cmd & " " & argsForCmd & " " & $line, "", [], nil, {poUsePath, poEvalCommand}, writeOutput)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
discard exec(cmd & " " & $line & " " & argsForCmd, "", [], nil, {poUsePath, poEvalCommand}, writeOutput)
|
|
|
|
historyAdd(line)
|
|
|
|
historyAdd(line)
|
|
|
|
line = readLine(cmdPrompt & "> ")
|
|
|
|
line = readLine(cmdPrompt & "> ")
|
|
|
|