doughboy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.DS_Store
5
+ *~*
6
+ *#*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@dough_boy
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dough_boy.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dough_boy (0.0.1)
5
+ open4 (~> 1.0.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.2)
11
+ open4 (1.0.1)
12
+ rspec (2.4.0)
13
+ rspec-core (~> 2.4.0)
14
+ rspec-expectations (~> 2.4.0)
15
+ rspec-mocks (~> 2.4.0)
16
+ rspec-core (2.4.0)
17
+ rspec-expectations (2.4.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.4.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ dough_boy!
26
+ rspec (~> 2.4.0)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Joshua Schairbaum
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE
data/README.markdown ADDED
@@ -0,0 +1,52 @@
1
+ Doughboy
2
+ ========
3
+
4
+ Doughboy is a Ruby library that strives to enable developers to easily make subprocessed shell calls.
5
+
6
+ Usage
7
+ --------
8
+
9
+ Doughboy provides a compossible interface to crafting shell commands.
10
+
11
+ command = Doughboy::Command.with_exec("ruby").with_options(["-v"])
12
+ command.run!
13
+
14
+ Commands components can be set directly on any object.
15
+
16
+ command = Doughboy::Command.new(:executable => "easy_install", :arguments => "some-python-library").run!
17
+
18
+ The preferred method is to use the composable chain methods.
19
+
20
+ Command Components
21
+ ------------------
22
+
23
+ Each command is composed of 3 separate components: executable, options, arguments.
24
+
25
+ ### Executable
26
+
27
+ When this component is set, the full-path is captured. If no path information could be determined, the executable passed will be used.
28
+
29
+ ### Options
30
+
31
+ Options are command line switches that either start w/ "-" or "--".
32
+
33
+ ### Arguments
34
+
35
+ Arguments are items that are passed to the executable. They might be a list of ip addresses or files.
36
+
37
+ Origin of the Name
38
+ ------------------
39
+
40
+ I wish I could say that it was meant to pay homage to the fighting men of the Lost Generation, but it's not. I was watching Boyz N The Hood.
41
+
42
+ ![Doughboy](http://2.bp.blogspot.com/_xdN0QQwsP1A/TDhzYsJhkpI/AAAAAAAAJZk/yjqX6ZNF1t8/s400/boyz_n_the_hood_xlg+ICE+Cube+crop.jpg)
43
+
44
+ Author
45
+ ------
46
+
47
+ Joshua Schairbaum \o\ joshua.schairbaum@gmail.com /o/ @jschairb
48
+
49
+ License
50
+ -------
51
+
52
+ See LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ import 'spec/spec.rake'
@@ -0,0 +1,10 @@
1
+ require 'autotest/fsevent'
2
+
3
+ require 'autotest_notification'
4
+ SPEAKING = true
5
+ DOOM_EDITION = true
6
+ BUUF = false
7
+ PENDING = false
8
+ STICKY = false
9
+ SUCCESS_SOUND = ''
10
+ FAILURE_SOUND = ''
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/doughboy.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "doughboy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "doughboy"
7
+ s.version = Doughboy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Joshua Schairbaum"]
10
+ s.email = ["joshua.schairbaum@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Easily run command-line programs. This }
13
+ s.description = %q{Doughboy is a Ruby library that strives to enable developers to easily make subprocessed shell calls.}
14
+
15
+ s.rubyforge_project = "doughboy"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('open4', '~>1.0.1')
23
+ s.add_development_dependency('rspec', "~>2.4.0")
24
+ end
@@ -0,0 +1,55 @@
1
+ module Doughboy
2
+ class Command
3
+ attr_accessor :arguments, :executable, :options
4
+
5
+ def initialize(*args)
6
+ if args.any?
7
+ local_args = args.first
8
+ self.arguments = local_args[:arguments]
9
+ self.executable = local_args[:executable]
10
+ self.options = local_args[:options]
11
+ end
12
+ end
13
+
14
+ def self.with_exec(command)
15
+ parsed_command = parse_command(command)
16
+ executable = parsed_command[:executable]
17
+ arguments = parsed_command[:arguments]
18
+ options = parsed_command[:options]
19
+
20
+ new(:executable => executable, :arguments => arguments, :options => options)
21
+ end
22
+
23
+ def command
24
+ [executable, options, arguments].join(" ")
25
+ end
26
+
27
+ def executable=(value)
28
+ return nil if value.nil?
29
+ full_path = `which #{value}`.strip
30
+ @executable = full_path != "" ? full_path : value
31
+ end
32
+
33
+ def options=(value)
34
+ return nil if value.nil?
35
+ @options = value.is_a?(Array) ? value : value.split(" ")
36
+ end
37
+
38
+ def run!
39
+ Output.new( Open4::popen4(command) )
40
+ end
41
+
42
+ private
43
+ def self.parse_command(command)
44
+ split_command = command.split(" ")
45
+ parsed_command = { }
46
+ args_and_opts = split_command[1..(split_command.size-1)]
47
+
48
+ parsed_command[:executable] = split_command[0]
49
+ parsed_command[:arguments] = args_and_opts.select { |t| !t.include?("-") }.join(" ")
50
+ parsed_command[:options] = args_and_opts.select { |t| t.include?("-") }
51
+ parsed_command
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,18 @@
1
+ module Doughboy
2
+ class Output
3
+ attr_accessor :pid, :stdin, :stdout, :stderr
4
+
5
+ def initialize(*args)
6
+ local_args = args.first
7
+ self.pid = local_args[0]
8
+ self.stdin = local_args[1]
9
+ self.stdout = local_args[2]
10
+ self.stderr = local_args[3]
11
+ end
12
+
13
+ def text
14
+ stdout.read.strip
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Doughboy
2
+ VERSION = "0.0.2"
3
+ end
data/lib/doughboy.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'open4'
2
+
3
+ require 'dough_boy/command'
4
+ require 'dough_boy/output'
5
+
6
+ module DoughBoy
7
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ module Doughboy
4
+ describe Command do
5
+ describe ".new" do
6
+ context "with a string argument" do
7
+ it "sets the executable"
8
+ end
9
+
10
+ context "with a hash argument" do
11
+ it "sets the arguments" do
12
+ command = Command.new(:arguments => "setup.py develop")
13
+ command.arguments.should_not be_nil
14
+ end
15
+
16
+ it "sets the executeable" do
17
+ command = Command.new(:executable => "python")
18
+ command.executable.should_not be_nil
19
+ end
20
+
21
+ it "sets the options" do
22
+ options = "-r -i"
23
+ command = Command.new(:options => options)
24
+ command.options.should_not be_nil
25
+ end
26
+
27
+ # Command.with_exec("python setup.py develop).run
28
+ # Command.with_exec("python").with_option("-r").with_arg("123456").run
29
+ # Command.with_exec("mi").with_options([]).with_args([]).run
30
+ # Command.with_exec("python") do |input|
31
+ # input.puts("exit()")
32
+ # end
33
+ end
34
+ end
35
+
36
+ describe ".with_exec" do
37
+ it "returns a Command" do
38
+ Command.with_exec("ruby").should be_kind_of(Command)
39
+ end
40
+
41
+ context "with a string of executable and argument" do
42
+ before(:each) do
43
+ @command_string = "ps aux"
44
+ end
45
+
46
+ it "assigns the executable" do
47
+ command = Command.with_exec(@command_string)
48
+ command.executable.should == `which ps`.strip
49
+ end
50
+
51
+ it "assigns the arguments" do
52
+ command = Command.with_exec(@command_string)
53
+ command.arguments.should == "aux"
54
+ end
55
+ end
56
+
57
+ context "with a string of executable, arguments, and options" do
58
+ before(:each) do
59
+ @command_string = "mi -r 212984"
60
+ end
61
+
62
+ it "assigns the executable" do
63
+ command = Command.with_exec(@command_string)
64
+ command.executable.should == `which mi`.strip
65
+ end
66
+
67
+ it "assigns the arguments" do
68
+ command = Command.with_exec(@command_string)
69
+ command.arguments.should == "212984"
70
+ end
71
+
72
+ it "assigns the options" do
73
+ command = Command.with_exec(@command_string)
74
+ command.options.should == ["-r"]
75
+ end
76
+ end
77
+
78
+ context "with an executable" do
79
+ it "assigns the executable" do
80
+ Command.with_exec("ruby").executable.should include("ruby")
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#arguments=" do
86
+ it 'sets the arguments' do
87
+ arguments = "setup.py develop"
88
+
89
+ command = Command.new(:arguments => arguments)
90
+ command.arguments.should == arguments
91
+ end
92
+ end
93
+
94
+ describe "#command" do
95
+ it "joins the executable, options, and arguments" do
96
+ full_command = "/bin/ps aux"
97
+ command = Command.new(:executable => "ps", :options => "", :arguments => "aux")
98
+ command.command.should == full_command
99
+ end
100
+ end
101
+
102
+ describe "#executable=" do
103
+ it "sets the full path of the executable" do
104
+ ruby = `which ruby`.strip
105
+
106
+ command = Command.new(:executable => "ruby")
107
+ command.executable.should == ruby
108
+ end
109
+
110
+ it "sets the value sent if no path could be determined" do
111
+ command = Command.new(:executable => "noexist")
112
+ command.executable.should == "noexist"
113
+ end
114
+ end
115
+
116
+ describe "#options=" do
117
+ context "with an array of options" do
118
+ it "sets the options as an array" do
119
+ options = ["-r", "-i"]
120
+ command = Command.new(:options => options)
121
+ command.options.should == options
122
+ end
123
+ end
124
+
125
+ context "with a string of options" do
126
+ options = "-r -i"
127
+ command = Command.new(:options => options)
128
+ command.options.should == ["-r", "-i"]
129
+ end
130
+ end
131
+
132
+ describe "#run!" do
133
+ it "runs the command" do
134
+ full_command = "/bin/ps aux"
135
+ command = Command.new()
136
+ command.stub!(:command).and_return(full_command)
137
+
138
+ Open4.should_receive(:popen4).with(full_command).
139
+ and_return([1234, StringIO.new, StringIO.new, StringIO.new])
140
+ command.run!
141
+ end
142
+
143
+ it "returns an output object" do
144
+ command = Command.new(:executable => "ps", :options => "", :arguments => "aux")
145
+ command.run!.should be_kind_of(Output)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module Doughboy
4
+ describe Output do
5
+ describe ".new" do
6
+ before(:each) do
7
+ #popen [pid, stdin, stdout, stderr]
8
+ @response = Open4::popen4("ps aux")
9
+ @output = Output.new(@response)
10
+ end
11
+
12
+ it "sets the pid" do
13
+ @output.pid.should == @response[0]
14
+ end
15
+
16
+ it "sets the stdin" do
17
+ @output.stdin.should == @response[1]
18
+ end
19
+
20
+ it "sets the stdout" do
21
+ @output.stdout.should == @response[2]
22
+ end
23
+
24
+ it "sets the stderr" do
25
+ @output.stderr.should == @response[3]
26
+ end
27
+ end
28
+
29
+ describe "#text" do
30
+ it "returns the stdout" do
31
+ response = Open4::popen4("ruby -v")
32
+ output = Output.new(response)
33
+
34
+ expected = `ruby -v`.strip
35
+ output.text.should == expected
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Doughboy do
4
+ end
data/spec/spec.rake ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec) do |t|
4
+ t.pattern = "./spec/**/*_spec.rb"
5
+ # Put spec opts in a file named .rspec in root
6
+ end
7
+
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require ::File.dirname(__FILE__) + '/../lib/doughboy.rb'
3
+
4
+ Rspec.configure do |config|
5
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doughboy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Joshua Schairbaum
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-04 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: open4
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 1
32
+ version: 1.0.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 4
46
+ - 0
47
+ version: 2.4.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: Doughboy is a Ruby library that strives to enable developers to easily make subprocessed shell calls.
51
+ email:
52
+ - joshua.schairbaum@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - .rspec
62
+ - .rvmrc
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.markdown
67
+ - Rakefile
68
+ - autotest/.autotest
69
+ - autotest/discover.rb
70
+ - doughboy.gemspec
71
+ - lib/doughboy.rb
72
+ - lib/doughboy/command.rb
73
+ - lib/doughboy/output.rb
74
+ - lib/doughboy/version.rb
75
+ - spec/doughboy/command_spec.rb
76
+ - spec/doughboy/output_spec.rb
77
+ - spec/doughboy_spec.rb
78
+ - spec/spec.rake
79
+ - spec/spec_helper.rb
80
+ has_rdoc: true
81
+ homepage: ""
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project: doughboy
108
+ rubygems_version: 1.3.7
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Easily run command-line programs. This
112
+ test_files:
113
+ - spec/doughboy/command_spec.rb
114
+ - spec/doughboy/output_spec.rb
115
+ - spec/doughboy_spec.rb
116
+ - spec/spec.rake
117
+ - spec/spec_helper.rb