command-builder 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +5 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +20 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/command-builder.gemspec +6 -3
- data/lib/command-builder.rb +14 -3
- data/test.rb +21 -13
- metadata +19 -8
data/CHANGES.txt
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
Command Builder
|
2
2
|
===============
|
3
3
|
|
4
|
-
**Command Builder** builds
|
5
|
-
|
6
|
-
|
4
|
+
**Command Builder** builds command runnable from shell by simple and
|
5
|
+
ellegant way. Also allows both synchronous executing or asynchronous
|
6
|
+
one using [EventMachine][1]. Here is an real example of call
|
7
|
+
to `jpegoptim`:
|
7
8
|
|
8
9
|
require "command-builder"
|
9
10
|
cmd = CommandBuilder::new(:jpegoptim)
|
@@ -16,18 +17,33 @@ command line from its arguments. Here is real example of call to
|
|
16
17
|
|
17
18
|
Value escaping and assignments are supported automatically of sure,
|
18
19
|
so call:
|
20
|
+
|
19
21
|
cmd.arg(:dest, './it\'s "my" folder')
|
20
22
|
|
21
23
|
…will be interpreted as `jpegoptim --dest="it's \"my\" folder"`. It also
|
22
24
|
takes spaces into the account.
|
23
25
|
|
26
|
+
### Executing
|
27
|
+
|
28
|
+
Command can be executed directly by call:
|
29
|
+
|
30
|
+
cmd.execute! # for synchronous executing or...
|
31
|
+
cmd.execute do |output| # ...for asynchronous executing
|
32
|
+
# ...
|
33
|
+
end
|
34
|
+
|
35
|
+
Asynchronous executing requires [EventMachine][1] environment to be run.
|
36
|
+
|
37
|
+
|
24
38
|
### Flexibility
|
25
39
|
|
26
40
|
Syntax described above is supported by default, but you can achieve for
|
27
41
|
example an Windows like syntax:
|
42
|
+
|
28
43
|
jpegoptim /m:2 -dest "directory"
|
29
44
|
|
30
45
|
…simply by assigning:
|
46
|
+
|
31
47
|
cmd.separators = ["/", ":", "-", " "]
|
32
48
|
|
33
49
|
For illustration, the default one is `["-", " ", "--", "="]`.
|
@@ -50,5 +66,6 @@ Copyright
|
|
50
66
|
Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
|
51
67
|
further details.
|
52
68
|
|
69
|
+
[1]: http://rubyeventmachine.com/
|
53
70
|
[2]: http://github.com/martinkozak/command-builder/issues
|
54
71
|
[3]: http://www.martinkozak.net/
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.name = "command-builder"
|
19
19
|
gem.homepage = "https://github.com/martinkozak/command-builder"
|
20
20
|
gem.license = "MIT"
|
21
|
-
gem.summary = 'Builds
|
21
|
+
gem.summary = 'Builds command runnable from shell by simple and ellegant way. Also allows both synchronous executing or asynchronous one using EventMachine.'
|
22
22
|
gem.email = "martinkozak@martinkozak.net"
|
23
23
|
gem.authors = ["Martin Kozák"]
|
24
24
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/command-builder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{command-builder}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Martin Kozák}]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-30}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -32,22 +32,25 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.licenses = [%q{MIT}]
|
33
33
|
s.require_paths = [%q{lib}]
|
34
34
|
s.rubygems_version = %q{1.8.5}
|
35
|
-
s.summary = %q{Builds
|
35
|
+
s.summary = %q{Builds command runnable from shell by simple and ellegant way. Also allows both synchronous executing or asynchronous one using EventMachine.}
|
36
36
|
|
37
37
|
if s.respond_to? :specification_version then
|
38
38
|
s.specification_version = 3
|
39
39
|
|
40
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
41
|
s.add_runtime_dependency(%q<hash-utils>, [">= 0.18.0"])
|
42
|
+
s.add_runtime_dependency(%q<pipe-run>, [">= 0.2.1"])
|
42
43
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
43
44
|
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
44
45
|
else
|
45
46
|
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
47
|
+
s.add_dependency(%q<pipe-run>, [">= 0.2.1"])
|
46
48
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
47
49
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
48
50
|
end
|
49
51
|
else
|
50
52
|
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
53
|
+
s.add_dependency(%q<pipe-run>, [">= 0.2.1"])
|
51
54
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
52
55
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
53
56
|
end
|
data/lib/command-builder.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require "hash-utils/object"
|
5
5
|
require "hash-utils/array"
|
6
|
+
require "pipe-run"
|
6
7
|
|
7
8
|
##
|
8
9
|
# Represents one command line command with arguments and parameters.
|
@@ -224,14 +225,21 @@ class CommandBuilder
|
|
224
225
|
end
|
225
226
|
|
226
227
|
##
|
227
|
-
# Executes the command.
|
228
|
+
# Executes the command. If block given, takes it output of the
|
229
|
+
# command and runs it asynchronously using EventMachine.
|
230
|
+
#
|
231
|
+
# @see https://github.com/martinkozak/pipe-run
|
232
|
+
# @param [Proc] block if asynchronous run
|
233
|
+
# @return [String] output of the command or nil if asynchronous
|
228
234
|
#
|
229
235
|
|
230
|
-
def execute
|
231
|
-
|
236
|
+
def execute(&block)
|
237
|
+
Pipe::run(self.to_s, &block)
|
232
238
|
end
|
233
239
|
|
234
240
|
alias :exec :execute
|
241
|
+
alias :"exec!" :execute
|
242
|
+
alias :"execute!" :execute
|
235
243
|
|
236
244
|
##
|
237
245
|
# Converts command to string.
|
@@ -256,12 +264,15 @@ class CommandBuilder
|
|
256
264
|
|
257
265
|
##
|
258
266
|
# Resets the arguments and parameters so prepares it for new build.
|
267
|
+
#
|
268
|
+
# @return [CommandBuilder] self instance
|
259
269
|
# @since 0.1.1
|
260
270
|
#
|
261
271
|
|
262
272
|
def reset!
|
263
273
|
@args = [ ]
|
264
274
|
@params = [ ]
|
275
|
+
self
|
265
276
|
end
|
266
277
|
|
267
278
|
alias :reset :"reset!"
|
data/test.rb
CHANGED
@@ -2,19 +2,27 @@
|
|
2
2
|
|
3
3
|
$:.push("./lib")
|
4
4
|
require "command-builder"
|
5
|
+
require "eventmachine"
|
5
6
|
|
6
|
-
|
7
|
-
cmd
|
8
|
-
cmd << :
|
9
|
-
cmd <<
|
10
|
-
cmd <<
|
11
|
-
cmd.
|
12
|
-
cmd.arg(:
|
13
|
-
cmd
|
14
|
-
cmd[:
|
15
|
-
|
7
|
+
EM::run do
|
8
|
+
cmd = CommandBuilder::new(:jpegoptim)
|
9
|
+
cmd << :preserve
|
10
|
+
cmd << :p
|
11
|
+
cmd << "file.jpg"
|
12
|
+
cmd << ["1 1.jpg", "2.jpg"]
|
13
|
+
cmd.arg(:max, 3)
|
14
|
+
cmd.arg(:m, 3)
|
15
|
+
cmd[:other] = "value"
|
16
|
+
cmd[:o] = "another '\" value"
|
17
|
+
puts cmd
|
16
18
|
|
17
|
-
puts cmd[:max].inspect
|
19
|
+
puts cmd[:max].inspect
|
20
|
+
cmd.execute do |out|
|
21
|
+
p out
|
22
|
+
end
|
23
|
+
|
24
|
+
p cmd.execute
|
18
25
|
|
19
|
-
cmd.reset!
|
20
|
-
puts cmd
|
26
|
+
cmd.reset!
|
27
|
+
puts cmd
|
28
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: command-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-30 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hash-utils
|
@@ -24,8 +24,19 @@ dependencies:
|
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: pipe-run
|
28
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
29
40
|
none: false
|
30
41
|
requirements:
|
31
42
|
- - ">="
|
@@ -33,10 +44,10 @@ dependencies:
|
|
33
44
|
version: 1.0.0
|
34
45
|
type: :development
|
35
46
|
prerelease: false
|
36
|
-
version_requirements: *
|
47
|
+
version_requirements: *id003
|
37
48
|
- !ruby/object:Gem::Dependency
|
38
49
|
name: jeweler
|
39
|
-
requirement: &
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
40
51
|
none: false
|
41
52
|
requirements:
|
42
53
|
- - ">="
|
@@ -44,7 +55,7 @@ dependencies:
|
|
44
55
|
version: 1.5.2
|
45
56
|
type: :development
|
46
57
|
prerelease: false
|
47
|
-
version_requirements: *
|
58
|
+
version_requirements: *id004
|
48
59
|
description:
|
49
60
|
email: martinkozak@martinkozak.net
|
50
61
|
executables: []
|
@@ -79,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
90
|
requirements:
|
80
91
|
- - ">="
|
81
92
|
- !ruby/object:Gem::Version
|
82
|
-
hash:
|
93
|
+
hash: -3638148640227519764
|
83
94
|
segments:
|
84
95
|
- 0
|
85
96
|
version: "0"
|
@@ -95,6 +106,6 @@ rubyforge_project:
|
|
95
106
|
rubygems_version: 1.8.5
|
96
107
|
signing_key:
|
97
108
|
specification_version: 3
|
98
|
-
summary: Builds
|
109
|
+
summary: Builds command runnable from shell by simple and ellegant way. Also allows both synchronous executing or asynchronous one using EventMachine.
|
99
110
|
test_files: []
|
100
111
|
|