Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

einhornsh: Parse the provided command-line

  • Loading branch information...
commit 2b922a8f20a390880f680b18b173c6704f49fba7 1 parent 9cd5acb
Greg Brockman authored September 27, 2012

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. 11  bin/einhornsh
11  bin/einhornsh
@@ -3,6 +3,7 @@ require 'logger'
3 3
 require 'optparse'
4 4
 
5 5
 require 'readline'
  6
+require 'shellwords'
6 7
 
7 8
 require 'rubygems'
8 9
 require 'einhorn'
@@ -20,13 +21,14 @@ module Einhorn
20 21
       emit('Type "quit" or "exit" to quit at any time')
21 22
 
22 23
       while line = Readline.readline('> ', true)
23  
-        if ['quit', 'exit'].include?(line)
  24
+        command, args = parse_command(line)
  25
+        if ['quit', 'exit'].include?(command)
24 26
           emit("Goodbye!")
25 27
           return
26 28
         end
27 29
 
28 30
         begin
29  
-          response = @client.command({'command' => line})
  31
+          response = @client.command({'command' => command, 'args' => args})
30 32
         rescue Errno::EPIPE => e
31 33
           emit("einhornsh: Error communicating with Einhorn: #{e} (#{e.class})")
32 34
           emit("einhornsh: Attempting to reconnect...")
@@ -43,6 +45,11 @@ module Einhorn
43 45
       end
44 46
     end
45 47
 
  48
+    def parse_command(line)
  49
+      command, *args = Shellwords.shellsplit(line)
  50
+      [command, args]
  51
+    end
  52
+
46 53
     def reconnect
47 54
       begin
48 55
         @client = Einhorn::Client.for_path(@path_to_socket)

0 notes on commit 2b922a8

Please sign in to comment.
Something went wrong with that request. Please try again.