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 +1 -1
- data/lib/doughboy/command.rb +15 -9
- data/lib/doughboy/version.rb +1 -1
- data/lib/doughboy.rb +5 -0
- data/spec/doughboy/command_spec.rb +6 -0
- data/spec/doughboy_spec.rb +6 -0
- metadata +2 -2
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
|
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.
|
data/lib/doughboy/command.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
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
|
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
|
-
|
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?("-") }
|
data/lib/doughboy/version.rb
CHANGED
data/lib/doughboy.rb
CHANGED
@@ -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
|
data/spec/doughboy_spec.rb
CHANGED