doughboy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -8,7 +8,7 @@ Usage
8
8
 
9
9
  Doughboy provides a compossible interface to crafting shell commands.
10
10
 
11
- command = Doughboy::Command.with_exec("ruby").with_options(["-v"])
11
+ command = Doughboy.with_exec("ruby").with_options(["-v"])
12
12
  command.run!
13
13
 
14
14
  Commands components can be set directly on any object.
@@ -1,27 +1,32 @@
1
1
  module Doughboy
2
2
  class Command
3
- attr_accessor :arguments, :executable, :options
3
+ attr_accessor :arguments, :executable, :full_arguments, :options
4
4
 
5
5
  def initialize(*args)
6
6
  if args.any?
7
7
  local_args = args.first
8
- self.arguments = local_args[:arguments]
9
- self.executable = local_args[:executable]
10
- self.options = local_args[:options]
8
+
9
+ %w( arguments executable options full_arguments).each do |arg|
10
+ self.send("#{arg}=", local_args[arg.intern])
11
+ end
11
12
  end
12
13
  end
13
14
 
14
15
  def self.with_exec(command)
15
16
  parsed_command = parse_command(command)
16
- executable = parsed_command[:executable]
17
- arguments = parsed_command[:arguments]
18
- options = parsed_command[:options]
19
17
 
20
- new(:executable => executable, :arguments => arguments, :options => options)
18
+ new( :executable => parsed_command[:executable],
19
+ :arguments => parsed_command[:arguments],
20
+ :options => parsed_command[:options],
21
+ :full_arguments => parsed_command[:full_arguments])
21
22
  end
22
23
 
23
24
  def command
24
- [executable, options, arguments].join(" ")
25
+ if full_arguments
26
+ [executable, full_arguments].join(" ")
27
+ else
28
+ [executable, options, arguments].join(" ")
29
+ end
25
30
  end
26
31
 
27
32
  def executable=(value)
@@ -45,6 +50,7 @@ module Doughboy
45
50
  parsed_command = { }
46
51
  args_and_opts = split_command[1..(split_command.size-1)]
47
52
 
53
+ parsed_command[:full_arguments] = args_and_opts
48
54
  parsed_command[:executable] = split_command[0]
49
55
  parsed_command[:arguments] = args_and_opts.select { |t| !t.include?("-") }.join(" ")
50
56
  parsed_command[:options] = args_and_opts.select { |t| t.include?("-") }
@@ -1,3 +1,3 @@
1
1
  module Doughboy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/doughboy.rb CHANGED
@@ -4,4 +4,9 @@ require 'doughboy/command'
4
4
  require 'doughboy/output'
5
5
 
6
6
  module Doughboy
7
+
8
+ def self.with_exec(command)
9
+ Command.with_exec(command)
10
+ end
11
+
7
12
  end
@@ -97,6 +97,12 @@ module Doughboy
97
97
  command = Command.new(:executable => "ps", :options => "", :arguments => "aux")
98
98
  command.command.should == full_command
99
99
  end
100
+
101
+ it "returns them in the proper order" do
102
+ python = `which python`.strip
103
+ command = Command.with_exec("python mbu_information.py -r 218298")
104
+ command.command.should == "#{python} mbu_information.py -r 218298"
105
+ end
100
106
  end
101
107
 
102
108
  describe "#executable=" do
@@ -1,4 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Doughboy do
4
+
5
+ describe "with_exec" do
6
+ it "returns a command" do
7
+ Doughboy.with_exec("ruby -v").should be_kind_of(Doughboy::Command)
8
+ end
9
+ end
4
10
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Schairbaum