lucie-cmd 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lucie-cmd/commands.rb +30 -5
- data/test/functional/sh_test.rb +24 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bcbc57fe509cfa7ca24494812a5af89113184f3
|
4
|
+
data.tar.gz: e2dc4c4c25c467287773478a09414d105b881a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff3b5da9dce13233b9f803bd20fc1b2a2ee230d78b4077b0c1edee29afb399a28e15395cf20eb48ff735545861ba9e6748a921a716ecf87c39ae00297c27660
|
7
|
+
data.tar.gz: 7ab81b5d27644870d8a6deadc80a36b5e0042c30734e50de89caa3286a5fd6cd6262e1fa92d309c63e47b6cd89969ed091d6851f69454fb77cc1f63a50a00ec3
|
data/lib/lucie-cmd/commands.rb
CHANGED
@@ -7,7 +7,8 @@ module Lucie
|
|
7
7
|
|
8
8
|
def sh(*args)
|
9
9
|
@commands_helper ||= CommandsHelper.new
|
10
|
-
@commands_helper.sh(*args)
|
10
|
+
status = @commands_helper.sh(*args)
|
11
|
+
status.to_i == 0
|
11
12
|
end
|
12
13
|
|
13
14
|
def cd(*args)
|
@@ -23,6 +24,11 @@ module Lucie
|
|
23
24
|
@commands_helper.status
|
24
25
|
end
|
25
26
|
|
27
|
+
def on(opts = [])
|
28
|
+
@commands_helper ||= CommandsHelper.new
|
29
|
+
@commands_helper.on(Array(opts))
|
30
|
+
end
|
31
|
+
|
26
32
|
private
|
27
33
|
|
28
34
|
class CommandsHelper
|
@@ -31,25 +37,44 @@ module Lucie
|
|
31
37
|
def initialize
|
32
38
|
@stderr = $stderr
|
33
39
|
@pwd = Dir.pwd
|
40
|
+
@opts = []
|
34
41
|
end
|
35
42
|
|
36
43
|
def sh(*args)
|
37
44
|
command = args.join(" ")
|
38
|
-
|
39
|
-
|
45
|
+
|
46
|
+
if @opts.include? :show_command
|
47
|
+
puts "$ #{command}"
|
48
|
+
end
|
49
|
+
|
50
|
+
@status = Open4::popen4("cd \"#{pwd}\" && #{command}") do |pid, stdin, stdout, stderr|
|
51
|
+
@stdin, @stderr, @pid = stdin, stderr, pid
|
52
|
+
@output = ""
|
53
|
+
if !stdout.eof()
|
54
|
+
new_content = stdout.read
|
55
|
+
if @opts.include? :live_input
|
56
|
+
print new_content
|
57
|
+
end
|
58
|
+
@output << new_content
|
59
|
+
end
|
60
|
+
end
|
40
61
|
end
|
41
62
|
|
42
63
|
def output
|
43
|
-
@
|
64
|
+
@output
|
44
65
|
end
|
45
66
|
|
46
67
|
def status
|
47
|
-
@status.to_i % 255
|
68
|
+
@status.exitstatus.to_i % 255
|
48
69
|
end
|
49
70
|
|
50
71
|
def pwd=(val)
|
51
72
|
@pwd = File.expand_path(val, @pwd)
|
52
73
|
end
|
74
|
+
|
75
|
+
def on(opts = [])
|
76
|
+
@opts = @opts | opts
|
77
|
+
end
|
53
78
|
end
|
54
79
|
end
|
55
80
|
end
|
data/test/functional/sh_test.rb
CHANGED
@@ -46,4 +46,28 @@ class ShTest < MiniTest::Spec
|
|
46
46
|
th2.join
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should return true if response status of the command was 0" do
|
50
|
+
assert_equal true, sh("true")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return false if the response status of the command was not 0" do
|
54
|
+
assert_equal false, sh("false")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to put the output realtime" do
|
58
|
+
on :live_input
|
59
|
+
out, err = capture_io do
|
60
|
+
sh "echo test"
|
61
|
+
end
|
62
|
+
assert_equal "test\n", out
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be able to show the command" do
|
66
|
+
on :show_command
|
67
|
+
out, err = capture_io do
|
68
|
+
sh "echo test"
|
69
|
+
end
|
70
|
+
assert_equal "$ echo test\n", out
|
71
|
+
end
|
72
|
+
|
49
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucie-cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nucc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.0.
|
118
|
+
rubygems_version: 2.0.3
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Library part of Lucie framework. Use this gem with Lucie if you want to run
|