execute_shell 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +8 -7
- data/Gemfile.lock +5 -3
- data/execute_shell.gemspec +3 -3
- data/lib/execute_shell.rb +1 -1
- data/lib/execute_shell/execute_shell.rb +5 -3
- data/rakefile +0 -120
- metadata +18 -18
- data/lib/execute_shell/script_env.rb +0 -81
data/Gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem 'Platform', '~> 0.4.0', :group => [:rake, :test],
|
4
|
-
:require => 'platform'
|
5
|
-
gem 'open4', '~> 1.0.1', :group => [:rake, :test]
|
6
|
-
gem 'win32-open3-19', '~> 0.0.1', :group => [:rake, :test], :require => 'open3'
|
7
|
-
|
8
3
|
group :rake do
|
9
|
-
|
10
|
-
|
4
|
+
gem 'rake_tasks', '~> 0.0.1'
|
5
|
+
end
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'Platform', '~> 0.4.0', :require => 'platform'
|
9
|
+
gem 'app_mode', '~> 0.0.1'
|
10
|
+
gem 'open4', '~> 1.0.1'
|
11
|
+
gem 'win32-open3-19', '~> 0.0.1', :require => 'open3'
|
11
12
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,9 +2,11 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
Platform (0.4.0)
|
5
|
-
|
5
|
+
app_mode (0.0.1)
|
6
6
|
open4 (1.0.1)
|
7
7
|
rake (0.8.7)
|
8
|
+
rake_tasks (0.0.1)
|
9
|
+
rake (~> 0.8.7)
|
8
10
|
win32-open3-19 (0.0.1)
|
9
11
|
|
10
12
|
PLATFORMS
|
@@ -12,7 +14,7 @@ PLATFORMS
|
|
12
14
|
|
13
15
|
DEPENDENCIES
|
14
16
|
Platform (~> 0.4.0)
|
15
|
-
|
17
|
+
app_mode (~> 0.0.1)
|
16
18
|
open4 (~> 1.0.1)
|
17
|
-
|
19
|
+
rake_tasks (~> 0.0.1)
|
18
20
|
win32-open3-19 (~> 0.0.1)
|
data/execute_shell.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'execute_shell'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.4'
|
4
4
|
|
5
5
|
s.summary = 'Cross-platform shell commands.'
|
6
6
|
s.description = 'Execute Shell provides ' +
|
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'Platform', '~> 0.4.0'
|
22
22
|
s.add_dependency 'open4', '~> 1.0.1'
|
23
23
|
s.add_dependency 'win32-open3-19', '~> 0.0.1'
|
24
|
+
s.add_dependency 'app_mode', '~> 0.0.1'
|
24
25
|
|
25
|
-
s.add_development_dependency '
|
26
|
-
s.add_development_dependency 'highline', '~> 1.6.1'
|
26
|
+
s.add_development_dependency 'rake_tasks', '~> 0.0.1'
|
27
27
|
|
28
28
|
s.has_rdoc = true
|
29
29
|
end
|
data/lib/execute_shell.rb
CHANGED
@@ -34,6 +34,8 @@
|
|
34
34
|
|
35
35
|
# Contains methods for returning output from console commands.
|
36
36
|
module ExecuteShell
|
37
|
+
# Indicates the mode that ExecuteShell is running in.
|
38
|
+
ExecuteShellMode = AppMode.new(:production)
|
37
39
|
|
38
40
|
# Returns output from a console command.
|
39
41
|
# ==== Input
|
@@ -62,7 +64,7 @@ module ExecuteShell
|
|
62
64
|
path ||= Dir.getwd
|
63
65
|
|
64
66
|
begin
|
65
|
-
STDOUT.puts command if
|
67
|
+
STDOUT.puts command if ExecuteShellMode.development
|
66
68
|
|
67
69
|
block = case Platform::IMPL
|
68
70
|
when :mingw
|
@@ -145,7 +147,7 @@ module ExecuteShell
|
|
145
147
|
def format_error(exception)
|
146
148
|
error_format = '%s: %s%s'
|
147
149
|
error_format % [exception.class, exception.message,
|
148
|
-
|
150
|
+
ExecuteShellMode.development ? "\n#{exception.backtrace.join("\n")}" : '']
|
149
151
|
end
|
150
152
|
|
151
153
|
# Raises a NotImplementedError.
|
@@ -172,7 +174,7 @@ module ExecuteShell
|
|
172
174
|
original = File.expand_path(Dir.getwd)
|
173
175
|
out = nil
|
174
176
|
|
175
|
-
STDOUT.puts path if
|
177
|
+
STDOUT.puts path if ExecuteShellMode.development
|
176
178
|
|
177
179
|
begin
|
178
180
|
Dir.chdir path unless path == original
|
data/rakefile
CHANGED
@@ -1,122 +1,2 @@
|
|
1
|
-
root_path = File.expand_path(File.dirname(__FILE__))
|
2
1
|
require 'bundler'
|
3
2
|
Bundler.require :rake
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rake/rdoctask'
|
6
|
-
require 'rake/clean'
|
7
|
-
require_relative 'lib/execute_shell'
|
8
|
-
|
9
|
-
include ExecuteShell
|
10
|
-
|
11
|
-
task :default => [:tests]
|
12
|
-
|
13
|
-
# Include any ruby files in the tasks folder.
|
14
|
-
task_files = Dir[
|
15
|
-
File.join(File.expand_path(File.dirname(__FILE__)), 'tasks', '*.rb')]
|
16
|
-
|
17
|
-
task_files.each do |rake_file|
|
18
|
-
require rake_file
|
19
|
-
end
|
20
|
-
|
21
|
-
# Add a task to run all tests.
|
22
|
-
Rake::TestTask.new('tests') do |task|
|
23
|
-
task.pattern = 'test/*_test.rb'
|
24
|
-
task.verbose = true
|
25
|
-
task.warning = true
|
26
|
-
end
|
27
|
-
Rake::Task[:tests].comment = 'Run all tests'
|
28
|
-
|
29
|
-
################################################################################
|
30
|
-
namespace :test do
|
31
|
-
################################################################################
|
32
|
-
file_list = Dir['test/*_test.rb']
|
33
|
-
|
34
|
-
# Add a distinct test task for each test file.
|
35
|
-
file_list.each do |item|
|
36
|
-
# Get the name to use for the task by removing '_test.rb' from the name.
|
37
|
-
task_name = File.basename(item, '.rb').gsub(/_test$/, '')
|
38
|
-
|
39
|
-
# Add each test.
|
40
|
-
Rake::TestTask.new(task_name) do |task|
|
41
|
-
task.pattern = item
|
42
|
-
task.verbose = true
|
43
|
-
task.warning = true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
################################################################################
|
47
|
-
end # :test
|
48
|
-
################################################################################
|
49
|
-
|
50
|
-
################################################################################
|
51
|
-
namespace :rdoc do
|
52
|
-
################################################################################
|
53
|
-
|
54
|
-
# Set the paths used by each of the rdoc options.
|
55
|
-
RDOC_FILES = {
|
56
|
-
:all => ['**/*.rb'],
|
57
|
-
:test => ['test/lib/**/*.rb'],
|
58
|
-
:app => [
|
59
|
-
'*.rb',
|
60
|
-
'lib/**/*.rb',
|
61
|
-
],
|
62
|
-
}
|
63
|
-
|
64
|
-
# Loop through the typs of rdoc files to generate an rdoc task for each one.
|
65
|
-
RDOC_FILES.keys.each do |rdoc_task|
|
66
|
-
Rake::RDocTask.new(
|
67
|
-
:rdoc => rdoc_task,
|
68
|
-
:clobber_rdoc => "#{rdoc_task}:clobber",
|
69
|
-
:rerdoc => "#{rdoc_task}:force") do |rdtask|
|
70
|
-
rdtask.rdoc_dir = "doc/#{rdoc_task}"
|
71
|
-
rdtask.options << '--charset' << 'utf8'
|
72
|
-
rdtask.rdoc_files.include RDOC_FILES[rdoc_task], 'README'
|
73
|
-
rdtask.main = 'README'
|
74
|
-
end
|
75
|
-
|
76
|
-
Rake::Task[rdoc_task].comment =
|
77
|
-
"Generate #{rdoc_task} RDoc documentation."
|
78
|
-
end
|
79
|
-
################################################################################
|
80
|
-
end # :rdoc
|
81
|
-
################################################################################
|
82
|
-
|
83
|
-
desc 'Search for a string in all files using a case insensitive search.'
|
84
|
-
task :grep, [:text] do |task, args|
|
85
|
-
# Set default search text to t-o-d-o.
|
86
|
-
# It is done this way to prevent coming up in the search itself.
|
87
|
-
args.with_defaults(:text => 't' + 'o' + 'd' + 'o')
|
88
|
-
|
89
|
-
# Use the sample color scheme, since it provides us with bold red via :error.
|
90
|
-
HighLine.color_scheme = HighLine::SampleColorScheme.new
|
91
|
-
COLOR = "<%%= color('%s', :error) %%>"
|
92
|
-
|
93
|
-
notification = "\nSearching for '%s':\n\n"
|
94
|
-
|
95
|
-
# Output the text that is being searched for.
|
96
|
-
case Platform::IMPL
|
97
|
-
when :linux
|
98
|
-
notification = notification % [COLOR % args[:text]]
|
99
|
-
when :mingw
|
100
|
-
notification = notification % args[:text]
|
101
|
-
else
|
102
|
-
raise_not_implemented('grep')
|
103
|
-
end
|
104
|
-
|
105
|
-
say notification
|
106
|
-
|
107
|
-
command = "grep #{args[:text]} * -ri"
|
108
|
-
success, output = shell(command)
|
109
|
-
|
110
|
-
# Send the results to the console.
|
111
|
-
case Platform::IMPL
|
112
|
-
when :linux
|
113
|
-
output = output.gsub(/(#{args[:text]})/i, COLOR % '\1')
|
114
|
-
when :mingw
|
115
|
-
else
|
116
|
-
raise_not_implemented('grep')
|
117
|
-
end
|
118
|
-
|
119
|
-
say output
|
120
|
-
end
|
121
|
-
|
122
|
-
CLOBBER.include('help')
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Herrick
|
@@ -19,7 +19,6 @@ default_executable:
|
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: Platform
|
22
|
-
prerelease: false
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
23
|
none: false
|
25
24
|
requirements:
|
@@ -31,10 +30,10 @@ dependencies:
|
|
31
30
|
- 0
|
32
31
|
version: 0.4.0
|
33
32
|
type: :runtime
|
33
|
+
prerelease: false
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: open4
|
37
|
-
prerelease: false
|
38
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
38
|
none: false
|
40
39
|
requirements:
|
@@ -46,10 +45,10 @@ dependencies:
|
|
46
45
|
- 1
|
47
46
|
version: 1.0.1
|
48
47
|
type: :runtime
|
48
|
+
prerelease: false
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: win32-open3-19
|
52
|
-
prerelease: false
|
53
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
53
|
none: false
|
55
54
|
requirements:
|
@@ -61,36 +60,37 @@ dependencies:
|
|
61
60
|
- 1
|
62
61
|
version: 0.0.1
|
63
62
|
type: :runtime
|
63
|
+
prerelease: false
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
67
|
-
prerelease: false
|
66
|
+
name: app_mode
|
68
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
68
|
none: false
|
70
69
|
requirements:
|
71
|
-
- -
|
70
|
+
- - ~>
|
72
71
|
- !ruby/object:Gem::Version
|
73
72
|
segments:
|
74
73
|
- 0
|
75
|
-
-
|
76
|
-
-
|
77
|
-
version: 0.
|
78
|
-
type: :
|
74
|
+
- 0
|
75
|
+
- 1
|
76
|
+
version: 0.0.1
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
79
|
version_requirements: *id004
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
82
|
-
prerelease: false
|
81
|
+
name: rake_tasks
|
83
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
83
|
none: false
|
85
84
|
requirements:
|
86
85
|
- - ~>
|
87
86
|
- !ruby/object:Gem::Version
|
88
87
|
segments:
|
88
|
+
- 0
|
89
|
+
- 0
|
89
90
|
- 1
|
90
|
-
|
91
|
-
- 1
|
92
|
-
version: 1.6.1
|
91
|
+
version: 0.0.1
|
93
92
|
type: :development
|
93
|
+
prerelease: false
|
94
94
|
version_requirements: *id005
|
95
95
|
description: Execute Shell provides cross-platform shell command execution.
|
96
96
|
email: tthetoad@gmail.com
|
@@ -102,7 +102,6 @@ extra_rdoc_files:
|
|
102
102
|
- README
|
103
103
|
files:
|
104
104
|
- lib/execute_shell/execute_shell.rb
|
105
|
-
- lib/execute_shell/script_env.rb
|
106
105
|
- lib/execute_shell.rb
|
107
106
|
- Gemfile.lock
|
108
107
|
- README
|
@@ -126,6 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
125
|
requirements:
|
127
126
|
- - ">="
|
128
127
|
- !ruby/object:Gem::Version
|
128
|
+
hash: -3169303462163591821
|
129
129
|
segments:
|
130
130
|
- 0
|
131
131
|
version: "0"
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# This file contains a class to manage information about the environment.
|
2
|
-
|
3
|
-
#--
|
4
|
-
################################################################################
|
5
|
-
# Copyright (C) 2011 Travis Herrick #
|
6
|
-
################################################################################
|
7
|
-
# #
|
8
|
-
# \v^V,^!v\^/ #
|
9
|
-
# ~% %~ #
|
10
|
-
# { _ _ } #
|
11
|
-
# ( * - ) #
|
12
|
-
# | / | #
|
13
|
-
# \ _, / #
|
14
|
-
# \__.__/ #
|
15
|
-
# #
|
16
|
-
################################################################################
|
17
|
-
# This program is free software: you can redistribute it #
|
18
|
-
# and/or modify it under the terms of the GNU General Public License #
|
19
|
-
# as published by the Free Software Foundation, #
|
20
|
-
# either version 3 of the License, or (at your option) any later version. #
|
21
|
-
# #
|
22
|
-
# Commercial licensing may be available for a fee under a different license. #
|
23
|
-
################################################################################
|
24
|
-
# This program is distributed in the hope that it will be useful, #
|
25
|
-
# but WITHOUT ANY WARRANTY; #
|
26
|
-
# without even the implied warranty of MERCHANTABILITY #
|
27
|
-
# or FITNESS FOR A PARTICULAR PURPOSE. #
|
28
|
-
# See the GNU General Public License for more details. #
|
29
|
-
# #
|
30
|
-
# You should have received a copy of the GNU General Public License #
|
31
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
32
|
-
################################################################################
|
33
|
-
#++
|
34
|
-
|
35
|
-
# This class manages environment information.
|
36
|
-
class ScriptEnv
|
37
|
-
# Contains valid environments for the script.
|
38
|
-
STATES = {
|
39
|
-
:development => :development,
|
40
|
-
:test => :testing,
|
41
|
-
:production => :production,
|
42
|
-
}
|
43
|
-
|
44
|
-
# Indicates the current environment of the script.
|
45
|
-
@@env = nil
|
46
|
-
|
47
|
-
class << self
|
48
|
-
# Retrieves the current environment setting.
|
49
|
-
def env
|
50
|
-
if @@env.nil? && File.expand_path(Dir.getwd) ==
|
51
|
-
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
52
|
-
return STATES[:development]
|
53
|
-
else
|
54
|
-
return STATES[@@env] || STATES[:production]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Black magic.
|
59
|
-
#
|
60
|
-
# Allows the getting and setting of the 'state' of the script.
|
61
|
-
# Only one environment can be active at a time.
|
62
|
-
# Setting one environment to true means the others are false.
|
63
|
-
# ==== Input
|
64
|
-
# [method : Symbol] The method that was called.
|
65
|
-
# [*args : Array] Any arguments that were passed in.
|
66
|
-
# [&block : Block] A block, if specified.
|
67
|
-
def method_missing(method, *args, &block)
|
68
|
-
if STATES.keys.include?(method.to_s.sub(/=$/, '').to_sym)
|
69
|
-
if method.to_s.match(/=$/) # Setter method.
|
70
|
-
value = args && args.shift || nil
|
71
|
-
@@env = method.to_s[0..-2].to_sym if value == true
|
72
|
-
else # ------------------- # Getter method.
|
73
|
-
states = STATES.select { |k, v| v == env }
|
74
|
-
return !states[method].nil?
|
75
|
-
end
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|