command_exec 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +16 -17
- data/Gemfile.lock +23 -49
- data/Rakefile +49 -1
- data/lib/command_exec/command.rb +35 -22
- data/lib/command_exec/version.rb +1 -1
- data/lib/command_exec.rb +7 -2
- data/script/terminal +12 -0
- data/spec/command/command_spec.rb +33 -8
- data/spec/spec_helper.rb +2 -0
- metadata +18 -7
data/Gemfile
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
source
|
1
|
+
source :rubygems
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in
|
3
|
+
# Specify your gem's dependencies in workplace-letter_generator.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
group :
|
7
|
-
gem '
|
8
|
-
gem 'fakefs'
|
9
|
-
gem 'fuubar'
|
10
|
-
gem 'github-markup'
|
11
|
-
gem 'guard'
|
12
|
-
gem 'guard-cucumber'
|
13
|
-
gem 'guard-rspec'
|
14
|
-
gem 'guard-yard'
|
15
|
-
gem 'libnotify'
|
16
|
-
gem 'pry'
|
17
|
-
gem 'rb-inotify'
|
18
|
-
gem 'rb-readline'
|
19
|
-
gem 'redcarpet' , '~>1.17.2'
|
6
|
+
group :test do
|
7
|
+
gem 'rake'
|
20
8
|
gem 'rspec'
|
9
|
+
gem 'tmrb'
|
21
10
|
gem 'simplecov'
|
22
|
-
gem '
|
11
|
+
gem 'aruba'
|
12
|
+
gem 'fuubar'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :documentation do
|
23
16
|
gem 'yard'
|
17
|
+
gem 'redcarpet'
|
18
|
+
gem 'github-markup'
|
19
|
+
end
|
20
|
+
|
21
|
+
group :development do
|
22
|
+
gem 'tmrb'
|
24
23
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,60 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
command_exec (0.0
|
4
|
+
command_exec (0.1.0)
|
5
5
|
POpen4
|
6
6
|
colored
|
7
7
|
|
8
8
|
GEM
|
9
|
-
remote:
|
9
|
+
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
11
|
POpen4 (0.1.4)
|
12
12
|
Platform (>= 0.4.0)
|
13
13
|
open4
|
14
14
|
Platform (0.4.0)
|
15
|
+
aruba (0.4.11)
|
16
|
+
childprocess (>= 0.2.3)
|
17
|
+
cucumber (>= 1.1.1)
|
18
|
+
ffi (>= 1.0.11)
|
19
|
+
rspec (>= 2.7.0)
|
15
20
|
builder (3.0.0)
|
16
|
-
|
21
|
+
childprocess (0.3.4)
|
22
|
+
ffi (~> 1.0, >= 1.0.6)
|
17
23
|
colored (1.2)
|
18
|
-
cucumber (1.1
|
24
|
+
cucumber (1.2.1)
|
19
25
|
builder (>= 2.1.2)
|
20
|
-
diff-lcs (>= 1.1.
|
21
|
-
gherkin (~> 2.
|
26
|
+
diff-lcs (>= 1.1.3)
|
27
|
+
gherkin (~> 2.11.0)
|
22
28
|
json (>= 1.4.6)
|
23
|
-
term-ansicolor (>= 1.0.6)
|
24
29
|
diff-lcs (1.1.3)
|
25
|
-
|
26
|
-
ffi (1.0.11)
|
30
|
+
ffi (1.1.0)
|
27
31
|
fuubar (1.0.0)
|
28
32
|
rspec (~> 2.0)
|
29
33
|
rspec-instafail (~> 0.2.0)
|
30
34
|
ruby-progressbar (~> 0.0.10)
|
31
|
-
gherkin (2.
|
35
|
+
gherkin (2.11.1)
|
32
36
|
json (>= 1.4.6)
|
33
37
|
github-markup (0.7.1)
|
34
|
-
|
35
|
-
ffi (>= 0.5.0)
|
36
|
-
thor (~> 0.14.6)
|
37
|
-
guard-cucumber (0.7.5)
|
38
|
-
cucumber (>= 0.10)
|
39
|
-
guard (>= 0.8.3)
|
40
|
-
guard-rspec (0.6.0)
|
41
|
-
guard (>= 0.10.0)
|
42
|
-
guard-yard (1.0.2)
|
43
|
-
guard (>= 0.2.2)
|
44
|
-
yard (>= 0.7.0)
|
45
|
-
highline (1.6.11)
|
46
|
-
json (1.6.5)
|
47
|
-
libnotify (0.7.2)
|
48
|
-
method_source (0.7.1)
|
38
|
+
json (1.7.3)
|
49
39
|
multi_json (1.1.0)
|
50
40
|
open4 (1.3.0)
|
51
|
-
|
52
|
-
coderay (~> 1.0.5)
|
53
|
-
method_source (~> 0.7.1)
|
54
|
-
slop (>= 2.4.4, < 3)
|
55
|
-
rb-inotify (0.8.8)
|
56
|
-
ffi (>= 0.5.0)
|
57
|
-
rb-readline (0.4.2)
|
41
|
+
rake (0.9.2.2)
|
58
42
|
redcarpet (1.17.2)
|
59
43
|
rspec (2.9.0)
|
60
44
|
rspec-core (~> 2.9.0)
|
@@ -70,32 +54,22 @@ GEM
|
|
70
54
|
multi_json (~> 1.0)
|
71
55
|
simplecov-html (~> 0.5.3)
|
72
56
|
simplecov-html (0.5.3)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
highline
|
77
|
-
thor (0.14.6)
|
57
|
+
thor (0.15.4)
|
58
|
+
tmrb (1.2.7)
|
59
|
+
thor
|
78
60
|
yard (0.7.5)
|
79
61
|
|
80
62
|
PLATFORMS
|
81
63
|
ruby
|
82
64
|
|
83
65
|
DEPENDENCIES
|
66
|
+
aruba
|
84
67
|
command_exec!
|
85
|
-
cucumber
|
86
|
-
fakefs
|
87
68
|
fuubar
|
88
69
|
github-markup
|
89
|
-
|
90
|
-
|
91
|
-
guard-rspec
|
92
|
-
guard-yard
|
93
|
-
libnotify
|
94
|
-
pry
|
95
|
-
rb-inotify
|
96
|
-
rb-readline
|
97
|
-
redcarpet (~> 1.17.2)
|
70
|
+
rake
|
71
|
+
redcarpet
|
98
72
|
rspec
|
99
73
|
simplecov
|
100
|
-
|
74
|
+
tmrb
|
101
75
|
yard
|
data/Rakefile
CHANGED
@@ -1 +1,49 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'yard'
|
4
|
+
require 'rubygems/package_task'
|
5
|
+
|
6
|
+
YARD::Rake::YardocTask.new do |t|
|
7
|
+
t.files = ['lib/**/*.rb', 'README.md', 'LICENCE.md']
|
8
|
+
t.options = ['--output-dir=doc/yard', '--markup-provider=redcarpet', '--markup=markdown' ]
|
9
|
+
end
|
10
|
+
|
11
|
+
task :terminal do
|
12
|
+
sh "script/terminal"
|
13
|
+
end
|
14
|
+
|
15
|
+
task :term => :terminal
|
16
|
+
task :t => :terminal
|
17
|
+
|
18
|
+
namespace :version do
|
19
|
+
version_file = Dir.glob('lib/**/version.rb').first
|
20
|
+
|
21
|
+
task :bump do
|
22
|
+
|
23
|
+
new_version = ENV['VERSION']
|
24
|
+
|
25
|
+
version_string = %Q{ module DataUri
|
26
|
+
VERSION = '#{new_version}'
|
27
|
+
end}
|
28
|
+
|
29
|
+
File.open(version_file, "w") do |f|
|
30
|
+
f.write version_string.strip_heredoc
|
31
|
+
end
|
32
|
+
|
33
|
+
sh "git add #{version_file}"
|
34
|
+
sh "git commit -m 'version bump to #{new_version}'"
|
35
|
+
sh "git tag data_uri-#{new_version}"
|
36
|
+
end
|
37
|
+
|
38
|
+
task :show do
|
39
|
+
raw_version = File.open(version_file, "r").readlines.grep(/VERSION/).first
|
40
|
+
|
41
|
+
if raw_version
|
42
|
+
version = raw_version.chomp.match(/VERSION\s+=\s+["']([^'"]+)["']/) { $1 }
|
43
|
+
puts version
|
44
|
+
else
|
45
|
+
warn "Could not parse version file \"#{version_file}\""
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/command_exec/command.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'popen4'
|
4
|
-
require 'colored'
|
5
|
-
require 'logger'
|
6
|
-
|
7
3
|
# Classes concerning command execution
|
8
4
|
module CommandExec
|
9
5
|
# Run commands
|
@@ -31,7 +27,7 @@ module CommandExec
|
|
31
27
|
:error_keywords => [],
|
32
28
|
:working_directory => Dir.pwd,
|
33
29
|
:logfile => '',
|
34
|
-
:
|
30
|
+
:log_level => :info,
|
35
31
|
}.update opts
|
36
32
|
|
37
33
|
@logger = @opts[:logger]
|
@@ -41,6 +37,8 @@ module CommandExec
|
|
41
37
|
@error_keywords = @opts[:error_keywords]
|
42
38
|
@logfile = @opts[:logfile]
|
43
39
|
|
40
|
+
configure_logging
|
41
|
+
|
44
42
|
@working_directory = @opts[:working_directory]
|
45
43
|
Dir.chdir(working_directory)
|
46
44
|
|
@@ -48,6 +46,27 @@ module CommandExec
|
|
48
46
|
|
49
47
|
private
|
50
48
|
|
49
|
+
def configure_logging
|
50
|
+
case @opts[:log_level]
|
51
|
+
when :debug
|
52
|
+
@logger.level = Logger::DEBUG
|
53
|
+
when :error
|
54
|
+
@logger.level = Logger::ERROR
|
55
|
+
when :fatal
|
56
|
+
@logger.level = Logger::FATAL
|
57
|
+
when :info
|
58
|
+
@logger.level = Logger::INFO
|
59
|
+
when :unknown
|
60
|
+
@logger.level = Logger::UNKNOWN
|
61
|
+
when :warn
|
62
|
+
@logger.level = Logger::WARN
|
63
|
+
when :silent
|
64
|
+
@logger.instance_variable_set(:@logdev, nil)
|
65
|
+
else
|
66
|
+
log_level = Logger::INFO
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
51
70
|
# Find utility path
|
52
71
|
#
|
53
72
|
# @param [Symbol] name Name of utility
|
@@ -61,7 +80,7 @@ module CommandExec
|
|
61
80
|
raise Exceptions::CommandNotFound
|
62
81
|
end
|
63
82
|
|
64
|
-
|
83
|
+
path
|
65
84
|
end
|
66
85
|
|
67
86
|
# Build string to execute command
|
@@ -73,20 +92,17 @@ module CommandExec
|
|
73
92
|
cmd += options.empty? ? "" : " #{options}"
|
74
93
|
cmd += parameter.empty? ? "" : " #{parameter}"
|
75
94
|
|
76
|
-
|
95
|
+
cmd
|
77
96
|
end
|
78
97
|
|
79
|
-
# Checks for errors
|
80
|
-
#
|
81
|
-
# @raise [String]
|
82
|
-
|
83
98
|
public
|
84
99
|
|
85
100
|
# Output the textual representation of a command
|
101
|
+
# public alias for build_cmd_string
|
86
102
|
#
|
87
103
|
# @return [String] command in text form
|
88
|
-
def to_txt
|
89
|
-
|
104
|
+
def to_txt
|
105
|
+
build_cmd_string
|
90
106
|
end
|
91
107
|
|
92
108
|
# Run the program
|
@@ -125,8 +141,7 @@ module CommandExec
|
|
125
141
|
|
126
142
|
@logger.info "#{@name.to_s}: #{msg}"
|
127
143
|
|
128
|
-
|
129
|
-
|
144
|
+
@result
|
130
145
|
end
|
131
146
|
|
132
147
|
# Read the content of the logfile
|
@@ -144,7 +159,7 @@ module CommandExec
|
|
144
159
|
end
|
145
160
|
end
|
146
161
|
|
147
|
-
|
162
|
+
content
|
148
163
|
end
|
149
164
|
|
150
165
|
# Decide if a program run was successful
|
@@ -184,8 +199,7 @@ module CommandExec
|
|
184
199
|
result << stdout
|
185
200
|
end
|
186
201
|
|
187
|
-
|
188
|
-
|
202
|
+
result
|
189
203
|
end
|
190
204
|
|
191
205
|
# Find error in stdout
|
@@ -203,8 +217,7 @@ module CommandExec
|
|
203
217
|
end
|
204
218
|
end
|
205
219
|
|
206
|
-
|
207
|
-
|
220
|
+
error_found
|
208
221
|
end
|
209
222
|
|
210
223
|
# Generate the message which is return to the user
|
@@ -221,7 +234,7 @@ module CommandExec
|
|
221
234
|
message.concat msg.flatten
|
222
235
|
end
|
223
236
|
|
224
|
-
|
237
|
+
message.join("\n")
|
225
238
|
end
|
226
239
|
|
227
240
|
# Constructur to initiate a new command and run it later
|
@@ -231,7 +244,7 @@ module CommandExec
|
|
231
244
|
command = new(name,opts)
|
232
245
|
command.run
|
233
246
|
|
234
|
-
|
247
|
+
command
|
235
248
|
end
|
236
249
|
|
237
250
|
end
|
data/lib/command_exec/version.rb
CHANGED
data/lib/command_exec.rb
CHANGED
data/script/terminal
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'tmrb'
|
4
|
+
|
5
|
+
tmux = TmRb::Multiplexer.new
|
6
|
+
#creates an empty window
|
7
|
+
tmux.new_session(session_name: 'command_exec')
|
8
|
+
|
9
|
+
tmux.new_window(:name => 'code', :command => "zsh -c 'vim -p lib/**/*.rb'")
|
10
|
+
tmux.new_window(:name => 'spec', :command => "zsh -c 'vim -p spec/**/*.rb'")
|
11
|
+
tmux.new_window(:name => 'features', :command => "zsh -c 'vim -p features/**/*.{rb,feature}'")
|
12
|
+
tmux.start
|
@@ -1,11 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Command do
|
4
|
-
let(:logger) {Logger.new(
|
4
|
+
let(:logger) {Logger.new(StringIO.new)}
|
5
5
|
#let(:logger) {Logger.new($stdout)}
|
6
|
-
let(:
|
7
|
-
|
8
|
-
let(:command) { Command.new(:echo , :debug=>debug, :logger => logger, :parameter => "hello world" , :error_keywords => %q[abc def], :working_directory => '/tmp' ) }
|
6
|
+
let(:log_level) {:info}
|
7
|
+
let(:command) { Command.new(:echo , :log_level => :silent, :logger => logger, :parameter => "hello world" , :error_keywords => %q[abc def], :working_directory => '/tmp' ) }
|
9
8
|
|
10
9
|
|
11
10
|
it "has a path" do
|
@@ -30,7 +29,7 @@ describe Command do
|
|
30
29
|
end
|
31
30
|
|
32
31
|
it "can be used to construct a command string, which can be executed" do
|
33
|
-
command = Command.new(:pdflatex, :
|
32
|
+
command = Command.new(:pdflatex, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-a -b")
|
34
33
|
command.send(:build_cmd_string).should == "/usr/bin/pdflatex -a -b index.tex blub.tex"
|
35
34
|
end
|
36
35
|
|
@@ -44,17 +43,17 @@ describe Command do
|
|
44
43
|
end
|
45
44
|
|
46
45
|
it "execute existing programs" do
|
47
|
-
command = Command.execute(:echo, :
|
46
|
+
command = Command.execute(:echo, :log_level => :silent, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b")
|
48
47
|
command.result.should == true
|
49
48
|
end
|
50
49
|
|
51
50
|
it "does not execute non-existing programs" do
|
52
|
-
command = Command.execute(:grep, :
|
51
|
+
command = Command.execute(:grep, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b")
|
53
52
|
command.result.should == false
|
54
53
|
end
|
55
54
|
|
56
55
|
it "checks if errors have happend during execution" do
|
57
|
-
lambda { Command.new(:echo1, :
|
56
|
+
lambda { Command.new(:echo1, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b") }.should raise_error CommandNotFound
|
58
57
|
end
|
59
58
|
|
60
59
|
it "decides which output should be returned to the user" do
|
@@ -95,6 +94,32 @@ describe Command do
|
|
95
94
|
command.send(:message, true ).should == "\e[1m\e[32mOK\e[0m\e[0m"
|
96
95
|
end
|
97
96
|
|
97
|
+
it "is very verbose and returns a lot of output" do
|
98
|
+
bucket = StringIO.new
|
99
|
+
logger = Logger.new(bucket)
|
100
|
+
Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :debug)
|
101
|
+
|
102
|
+
bucket.string.should =~ /OK/
|
103
|
+
end
|
104
|
+
|
105
|
+
it "is silent and returns no output" do
|
106
|
+
bucket = StringIO.new
|
107
|
+
logger = Logger.new(bucket)
|
108
|
+
Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :silent)
|
109
|
+
|
110
|
+
bucket.string.should == ""
|
111
|
+
end
|
112
|
+
|
113
|
+
# not completed
|
114
|
+
#it "use a log file if given" do
|
115
|
+
# application_log_file = Tempfile.new('command_exec_test')
|
116
|
+
# application_log_file.write "ERROR"
|
117
|
+
|
118
|
+
# binding.pry
|
119
|
+
# Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :silent, :logfile => application_log_file, :error_keywords => %W[ERROR])
|
120
|
+
|
121
|
+
#end
|
122
|
+
|
98
123
|
|
99
124
|
|
100
125
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: POpen4
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: colored
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
description: This adds bells and whistles to ease shell command execution
|
37
47
|
email:
|
38
48
|
- dev@fedux.org
|
@@ -54,6 +64,7 @@ files:
|
|
54
64
|
- lib/command_exec/exceptions.rb
|
55
65
|
- lib/command_exec/spec_helper_module.rb
|
56
66
|
- lib/command_exec/version.rb
|
67
|
+
- script/terminal
|
57
68
|
- spec/command/command_spec.rb
|
58
69
|
- spec/spec_helper.rb
|
59
70
|
homepage: ''
|
@@ -76,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
87
|
version: '0'
|
77
88
|
requirements: []
|
78
89
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
90
|
+
rubygems_version: 1.8.24
|
80
91
|
signing_key:
|
81
92
|
specification_version: 3
|
82
93
|
summary: Helper gem to exectue arbitrary shell commands
|