sys_cmd 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sys_cmd.rb +35 -7
- data/lib/sys_cmd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0abba95b366a7cea45fc88aed525ce584b7210c1
|
4
|
+
data.tar.gz: 3b46e79596aaf87f60869895ed7b203cb9efbc34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a762ff57a7dc59365329bb486c076da0ac3b3bde8f525bc118dc19853a0eaca23acfc2188ad4d1bca89388aa0a377c99ee59e6b71423f06a509e152c2e80b1
|
7
|
+
data.tar.gz: eb1a4ac756232ab6488791331bf72bc69b74181107b3ac4eba0e95e49b47752eb73284df264ac52a77bdf3340fcb87721acb4b2e9841a9799f46b925d9384003
|
data/lib/sys_cmd.rb
CHANGED
@@ -24,19 +24,26 @@ module SysCmd
|
|
24
24
|
@command = ''
|
25
25
|
@command << (@options[command] || command)
|
26
26
|
@last_arg = :command
|
27
|
+
@stdin_data = nil
|
27
28
|
end
|
28
29
|
|
29
|
-
attr_reader :command, :shell
|
30
|
+
attr_reader :command, :shell, :stdin_data
|
30
31
|
|
31
32
|
def to_s
|
32
33
|
command
|
33
34
|
end
|
34
35
|
|
35
|
-
# Add an option
|
36
|
+
# Add an option to the command.
|
37
|
+
#
|
38
|
+
# option '-x' # flag-style option
|
39
|
+
# option '--y' # long option
|
40
|
+
# option '/z' # Windows-style option
|
41
|
+
# options 'abc' # unprefixed option
|
42
|
+
#
|
43
|
+
# If the option +:os_prefix+ is true
|
36
44
|
# then the default system option switch will be used.
|
37
45
|
#
|
38
|
-
# option 'x' # will produce -x or /x
|
39
|
-
# option '-x' # will always produce -x
|
46
|
+
# option 'x', os_prefix: true # will produce -x or /x
|
40
47
|
#
|
41
48
|
# A value can be given as an option and will be space-separated from
|
42
49
|
# the option name:
|
@@ -66,7 +73,7 @@ module SysCmd
|
|
66
73
|
raise "Invalid number of arguments (0 or 1 expected)" if args.size > 1
|
67
74
|
return unless @shell.applicable?(options)
|
68
75
|
value = args.shift || options[:value]
|
69
|
-
if
|
76
|
+
if options[:os_prefix]
|
70
77
|
option = @shell.option_switch + option
|
71
78
|
else
|
72
79
|
option = option.dup
|
@@ -88,6 +95,14 @@ module SysCmd
|
|
88
95
|
@last_arg = :option
|
89
96
|
end
|
90
97
|
|
98
|
+
# An +os_option+ has automatically a OS-dependent prefix
|
99
|
+
def os_option(option, *args)
|
100
|
+
options = args.pop if args.last.is_a?(Hash)
|
101
|
+
options ||= {}
|
102
|
+
args.push options.merge(os_prefix: true)
|
103
|
+
option option, *args
|
104
|
+
end
|
105
|
+
|
91
106
|
# Add a filename to the command.
|
92
107
|
#
|
93
108
|
# file 'path/output'
|
@@ -170,6 +185,14 @@ module SysCmd
|
|
170
185
|
@last_arg = :argument
|
171
186
|
end
|
172
187
|
|
188
|
+
# Define data to be passed as standard input to the command
|
189
|
+
def input(data)
|
190
|
+
if @stdin_data
|
191
|
+
@stdin_data += data.to_s
|
192
|
+
else
|
193
|
+
@stdin_data = data.to_s
|
194
|
+
end
|
195
|
+
end
|
173
196
|
end
|
174
197
|
|
175
198
|
# An executable system command
|
@@ -178,9 +201,11 @@ module SysCmd
|
|
178
201
|
if command.respond_to?(:shell)
|
179
202
|
@command = command.command
|
180
203
|
@shell = command.shell
|
204
|
+
@stdin_data = command.stdin_data
|
181
205
|
else
|
182
206
|
@command = command
|
183
207
|
@shell = Shell.new(options)
|
208
|
+
@stdin_data = options[:stdin_data]
|
184
209
|
end
|
185
210
|
@output = nil
|
186
211
|
@status = nil
|
@@ -239,8 +264,9 @@ module SysCmd
|
|
239
264
|
else
|
240
265
|
command = [@command]
|
241
266
|
end
|
242
|
-
|
243
|
-
|
267
|
+
stdin_data = options[:stdin_data] || @stdin_data
|
268
|
+
if stdin_data
|
269
|
+
command << { stdin_data: stdin_data }
|
244
270
|
end
|
245
271
|
begin
|
246
272
|
case options[:error_output]
|
@@ -263,6 +289,8 @@ module SysCmd
|
|
263
289
|
@output
|
264
290
|
when :error_output
|
265
291
|
@error_output
|
292
|
+
when :command
|
293
|
+
self
|
266
294
|
else
|
267
295
|
@error ? nil : @status.success? ? true : false
|
268
296
|
end
|
data/lib/sys_cmd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys_cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Goizueta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: os
|