simple_shell 1.0.0 → 1.0.1
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/README.rdoc +60 -4
- data/VERSION +1 -1
- data/lib/simple_shell.rb +14 -6
- data/simple_shell.gemspec +2 -2
- data/spec/simple_shell_spec.rb +8 -0
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -1,9 +1,65 @@
|
|
1
|
-
=
|
1
|
+
= SimpleShell
|
2
2
|
|
3
|
-
|
3
|
+
A very simple, yet safe and sturdy wrapper around your shell.
|
4
|
+
|
5
|
+
gives you stdout
|
6
|
+
|
7
|
+
shell = SimpleShell.new()
|
8
|
+
res = shell.ls
|
9
|
+
res.out
|
10
|
+
=> a_file
|
11
|
+
b_file
|
12
|
+
c_file
|
13
|
+
|
14
|
+
gives you stderr
|
15
|
+
|
16
|
+
res = shell.ls("/path/not/exists")
|
17
|
+
res.err
|
18
|
+
=> "ls: cannot access /path/not/exists: No such file or directory"
|
19
|
+
|
20
|
+
gives you exit value
|
21
|
+
|
22
|
+
res.S?
|
23
|
+
=> #<Process::Status: pid 20743 exit 2>
|
24
|
+
shell.S?
|
25
|
+
=> #<Process::Status: pid 20743 exit 2>
|
26
|
+
|
27
|
+
gives you stdin
|
28
|
+
|
29
|
+
res = shell.sendmail("you@yourdomain.com") do |pipe|
|
30
|
+
pipe.puts message
|
31
|
+
end
|
32
|
+
|
33
|
+
is tied to it's location
|
34
|
+
|
35
|
+
shell = SimpleShell.new("/tmp")
|
36
|
+
shell.ls
|
37
|
+
=> # ... contents of tmp
|
38
|
+
shell.chdir "/home"
|
39
|
+
Errno::ENOENT:
|
40
|
+
Dir.chdir("/home")
|
41
|
+
shell.ls
|
42
|
+
=> # ... still, contents of tmp
|
43
|
+
|
44
|
+
provides you with a sub shell for location shifts
|
45
|
+
|
46
|
+
commands = shell.in("/home") do |sub|
|
47
|
+
sub.ls
|
48
|
+
sub.mkdir("joe")
|
49
|
+
end
|
50
|
+
commands.count
|
51
|
+
=> 2
|
52
|
+
commands.last.S?
|
53
|
+
=> #<Process::Status: pid 20760 exit 1>
|
54
|
+
|
55
|
+
lets you specify the environment
|
56
|
+
|
57
|
+
shell = SimpleShell.new(Dir.pwd, { 'MY_ENV' => 'my env' })
|
58
|
+
shell.echo '${MY_ENV}'
|
59
|
+
=> 'my env'
|
60
|
+
|
61
|
+
== Contributing to SimpleShell
|
4
62
|
|
5
|
-
== Contributing to simple_shell
|
6
|
-
|
7
63
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
64
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
65
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/simple_shell.rb
CHANGED
@@ -33,8 +33,14 @@ class SimpleShell
|
|
33
33
|
# SimpleShell.new
|
34
34
|
# SimpleShell.new("/path/to/base")
|
35
35
|
#
|
36
|
-
def initialize(base=Dir.pwd)
|
36
|
+
def initialize(base=Dir.pwd, env={})
|
37
|
+
if base.is_a?(Hash)
|
38
|
+
env = base
|
39
|
+
base = Dir.pwd
|
40
|
+
end
|
41
|
+
|
37
42
|
@base = base
|
43
|
+
@env = env
|
38
44
|
@commands = []
|
39
45
|
end
|
40
46
|
|
@@ -49,7 +55,7 @@ class SimpleShell
|
|
49
55
|
def in(dir, &block)
|
50
56
|
dir = File.join(@base, dir) if !File.exists?(dir) || dir !~ /^\//
|
51
57
|
|
52
|
-
shell = SimpleShell.new(dir)
|
58
|
+
shell = SimpleShell.new(dir, @env)
|
53
59
|
yield shell
|
54
60
|
return shell.commands
|
55
61
|
end
|
@@ -70,7 +76,7 @@ class SimpleShell
|
|
70
76
|
def system(*args, &block)
|
71
77
|
command = nil
|
72
78
|
Dir.chdir(@base) do
|
73
|
-
command = Command.new(@base)
|
79
|
+
command = Command.new(@base, @env)
|
74
80
|
command.execute(*args, &block)
|
75
81
|
end
|
76
82
|
|
@@ -107,17 +113,19 @@ class SimpleShell
|
|
107
113
|
class Command
|
108
114
|
attr_reader :out, :err, :S
|
109
115
|
|
110
|
-
def initialize(base)
|
116
|
+
def initialize(base, env={})
|
111
117
|
@base = base
|
118
|
+
@env = env
|
119
|
+
|
112
120
|
@out = ""
|
113
121
|
@err = ""
|
114
122
|
@S = -1
|
115
123
|
end
|
116
124
|
|
117
125
|
def execute(command, *args, &block)
|
118
|
-
$stderr.puts("#{command}, #{args}, #{@base}") if SimpleShell.noisy
|
126
|
+
$stderr.puts("#{@env} #{command}, #{args}, #{@base}") if SimpleShell.noisy
|
119
127
|
|
120
|
-
Open3.popen3("#{command}", *(args.collect { |a| "#{a}" }) , :chdir => @base) do |stdin, stdout, stderr, thread|
|
128
|
+
Open3.popen3(@env, "#{command}", *(args.collect { |a| "#{a}" }) , :chdir => @base) do |stdin, stdout, stderr, thread|
|
121
129
|
if block_given?
|
122
130
|
yield stdin
|
123
131
|
end
|
data/simple_shell.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "simple_shell"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Hartog C. de Mik"]
|
12
|
-
s.date = "2012-02-
|
12
|
+
s.date = "2012-02-06"
|
13
13
|
s.description = "A very simple, smart & elegant shell operations gem"
|
14
14
|
s.email = "hartog@organisedminds.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/simple_shell_spec.rb
CHANGED
@@ -63,4 +63,12 @@ describe SimpleShell do
|
|
63
63
|
SimpleShell.noisy = true
|
64
64
|
SimpleShell.noisy.should be_true
|
65
65
|
end
|
66
|
+
|
67
|
+
it "should allow for environment setting" do
|
68
|
+
shell = SimpleShell.new({ 'MY_ENV' => 'my environment' })
|
69
|
+
shell.printenv.out.should =~ /my environment/
|
70
|
+
|
71
|
+
shell = SimpleShell.new()
|
72
|
+
shell.printenv.out.should_not =~ /my environment/
|
73
|
+
end
|
66
74
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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-02-
|
12
|
+
date: 2012-02-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &89359440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.8.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *89359440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &89359170 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.12'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *89359170
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &89358920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *89358920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &89358670 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.8.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *89358670
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &89358390 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *89358390
|
69
69
|
description: A very simple, smart & elegant shell operations gem
|
70
70
|
email: hartog@organisedminds.com
|
71
71
|
executables: []
|
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 737581693
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|