command-builder 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +7 -0
- data/Gemfile +3 -4
- data/Gemfile.lock +7 -7
- data/README.md +2 -2
- data/Rakefile +3 -11
- data/VERSION +1 -1
- data/command-builder.gemspec +16 -15
- data/lib/command-builder.rb +21 -8
- data/test.rb +6 -2
- metadata +8 -9
data/CHANGES.txt
ADDED
data/Gemfile
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
|
-
|
5
|
-
gem "hash-utils", ">= 0.7.0"
|
4
|
+
gem "hash-utils", ">= 0.18.0"
|
6
5
|
|
7
6
|
# Add dependencies to develop your gem here.
|
8
7
|
# Include everything needed to run rake, tests, features, etc.
|
9
8
|
group :development do
|
10
|
-
gem "bundler", "
|
11
|
-
gem "jeweler", "
|
9
|
+
gem "bundler", ">= 1.0.0"
|
10
|
+
gem "jeweler", ">= 1.5.2"
|
12
11
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,17 +2,17 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
git (1.2.5)
|
5
|
-
hash-utils (0.
|
6
|
-
jeweler (1.
|
7
|
-
bundler (~> 1.0
|
5
|
+
hash-utils (0.18.0)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
8
|
git (>= 1.2.5)
|
9
9
|
rake
|
10
|
-
rake (0.
|
10
|
+
rake (0.9.2)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
13
|
ruby
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
|
-
bundler (
|
17
|
-
hash-utils (>= 0.
|
18
|
-
jeweler (
|
16
|
+
bundler (>= 1.0.0)
|
17
|
+
hash-utils (>= 0.18.0)
|
18
|
+
jeweler (>= 1.5.2)
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ command line from its arguments. Here is real example of call to
|
|
12
12
|
cmd << :preserve
|
13
13
|
cmd << "image.jpg"
|
14
14
|
|
15
|
-
cmd.to_s # will return 'jpegoptim -m 2 --preserve
|
15
|
+
cmd.to_s # will return 'jpegoptim -m 2 --preserve image.jpg'
|
16
16
|
|
17
17
|
Value escaping and assignments are supported automatically of sure,
|
18
18
|
so call:
|
@@ -50,5 +50,5 @@ Copyright
|
|
50
50
|
Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
|
51
51
|
further details.
|
52
52
|
|
53
|
-
[2]: http://github.com/martinkozak/
|
53
|
+
[2]: http://github.com/martinkozak/command-builder/issues
|
54
54
|
[3]: http://www.martinkozak.net/
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'bundler'
|
4
|
+
|
4
5
|
begin
|
5
6
|
Bundler.setup(:default, :development)
|
6
7
|
rescue Bundler::BundlerError => e
|
@@ -8,9 +9,10 @@ rescue Bundler::BundlerError => e
|
|
8
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
9
10
|
exit e.status_code
|
10
11
|
end
|
11
|
-
require 'rake'
|
12
12
|
|
13
|
+
require 'rake'
|
13
14
|
require 'jeweler'
|
15
|
+
|
14
16
|
Jeweler::Tasks.new do |gem|
|
15
17
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
18
|
gem.name = "command-builder"
|
@@ -25,13 +27,3 @@ Jeweler::Tasks.new do |gem|
|
|
25
27
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
28
|
end
|
27
29
|
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rake/rdoctask'
|
30
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
-
|
33
|
-
rdoc.rdoc_dir = 'rdoc'
|
34
|
-
rdoc.title = "qrpc #{version}"
|
35
|
-
rdoc.rdoc_files.include('README*')
|
36
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
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.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-
|
11
|
+
s.authors = [%q{Martin Kozák}]
|
12
|
+
s.date = %q{2011-07-24}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
]
|
18
18
|
s.files = [
|
19
19
|
".document",
|
20
|
+
"CHANGES.txt",
|
20
21
|
"Gemfile",
|
21
22
|
"Gemfile.lock",
|
22
23
|
"LICENSE.txt",
|
@@ -28,27 +29,27 @@ Gem::Specification.new do |s|
|
|
28
29
|
"test.rb"
|
29
30
|
]
|
30
31
|
s.homepage = %q{https://github.com/martinkozak/command-builder}
|
31
|
-
s.licenses = [
|
32
|
-
s.require_paths = [
|
33
|
-
s.rubygems_version = %q{1.5
|
32
|
+
s.licenses = [%q{MIT}]
|
33
|
+
s.require_paths = [%q{lib}]
|
34
|
+
s.rubygems_version = %q{1.8.5}
|
34
35
|
s.summary = %q{Builds call to some command runnable from shell command line from its arguments.}
|
35
36
|
|
36
37
|
if s.respond_to? :specification_version then
|
37
38
|
s.specification_version = 3
|
38
39
|
|
39
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
-
s.add_runtime_dependency(%q<hash-utils>, [">= 0.
|
41
|
-
s.add_development_dependency(%q<bundler>, ["
|
42
|
-
s.add_development_dependency(%q<jeweler>, ["
|
41
|
+
s.add_runtime_dependency(%q<hash-utils>, [">= 0.18.0"])
|
42
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
43
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
43
44
|
else
|
44
|
-
s.add_dependency(%q<hash-utils>, [">= 0.
|
45
|
-
s.add_dependency(%q<bundler>, ["
|
46
|
-
s.add_dependency(%q<jeweler>, ["
|
45
|
+
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
46
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
47
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
47
48
|
end
|
48
49
|
else
|
49
|
-
s.add_dependency(%q<hash-utils>, [">= 0.
|
50
|
-
s.add_dependency(%q<bundler>, ["
|
51
|
-
s.add_dependency(%q<jeweler>, ["
|
50
|
+
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
51
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
data/lib/command-builder.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
2
3
|
|
3
4
|
require "hash-utils/object"
|
5
|
+
require "hash-utils/array"
|
4
6
|
|
5
7
|
##
|
6
8
|
# Represents one command line command with arguments and parameters.
|
@@ -61,8 +63,7 @@ class CommandBuilder
|
|
61
63
|
def initialize(command, separators = ["-", " ", "--", "="])
|
62
64
|
@command = command
|
63
65
|
@separators = separators
|
64
|
-
|
65
|
-
@params = [ ]
|
66
|
+
self.reset!
|
66
67
|
end
|
67
68
|
|
68
69
|
##
|
@@ -167,9 +168,9 @@ class CommandBuilder
|
|
167
168
|
#
|
168
169
|
|
169
170
|
def add(option, value = nil)
|
170
|
-
if option.
|
171
|
+
if option.symbol? or not value.nil?
|
171
172
|
self.argument(option, value)
|
172
|
-
elsif option.
|
173
|
+
elsif option.array?
|
173
174
|
self.parameters(option)
|
174
175
|
else
|
175
176
|
self.parameter(option)
|
@@ -253,6 +254,18 @@ class CommandBuilder
|
|
253
254
|
return cmd
|
254
255
|
end
|
255
256
|
|
257
|
+
##
|
258
|
+
# Resets the arguments and parameters so prepares it for new build.
|
259
|
+
# @since 0.1.1
|
260
|
+
#
|
261
|
+
|
262
|
+
def reset!
|
263
|
+
@args = [ ]
|
264
|
+
@params = [ ]
|
265
|
+
end
|
266
|
+
|
267
|
+
alias :reset :"reset!"
|
268
|
+
|
256
269
|
|
257
270
|
private
|
258
271
|
|
@@ -268,18 +281,18 @@ class CommandBuilder
|
|
268
281
|
short = (name.length == 1)
|
269
282
|
|
270
283
|
if short
|
271
|
-
cmd << @separators
|
284
|
+
cmd << @separators.first
|
272
285
|
else
|
273
|
-
cmd << @separators
|
286
|
+
cmd << @separators.third
|
274
287
|
end
|
275
288
|
cmd << name
|
276
289
|
|
277
290
|
# Value
|
278
291
|
if not value.nil?
|
279
292
|
if short
|
280
|
-
cmd << @separators
|
293
|
+
cmd << @separators.second
|
281
294
|
else
|
282
|
-
cmd << @separators
|
295
|
+
cmd << @separators.fourth
|
283
296
|
end
|
284
297
|
cmd << self.quote(value.to_s)
|
285
298
|
end
|
data/test.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
$:.push("./lib")
|
4
|
+
require "command-builder"
|
4
5
|
|
5
6
|
cmd = CommandBuilder::new(:jpegoptim)
|
6
7
|
cmd << :preserve
|
7
8
|
cmd << :p
|
8
9
|
cmd << "file.jpg"
|
9
|
-
cmd << ["1.jpg", "2.jpg"]
|
10
|
+
cmd << ["1 1.jpg", "2.jpg"]
|
10
11
|
cmd.arg(:max, 3)
|
11
12
|
cmd.arg(:m, 3)
|
12
13
|
cmd[:other] = "value"
|
@@ -14,3 +15,6 @@ cmd[:o] = "another '\" value"
|
|
14
15
|
puts cmd
|
15
16
|
|
16
17
|
puts cmd[:max].inspect
|
18
|
+
|
19
|
+
cmd.reset!
|
20
|
+
puts cmd
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: command-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-07-24 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: hash-utils
|
@@ -20,7 +19,7 @@ dependencies:
|
|
20
19
|
requirements:
|
21
20
|
- - ">="
|
22
21
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
22
|
+
version: 0.18.0
|
24
23
|
type: :runtime
|
25
24
|
prerelease: false
|
26
25
|
version_requirements: *id001
|
@@ -29,7 +28,7 @@ dependencies:
|
|
29
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
30
|
requirements:
|
32
|
-
- -
|
31
|
+
- - ">="
|
33
32
|
- !ruby/object:Gem::Version
|
34
33
|
version: 1.0.0
|
35
34
|
type: :development
|
@@ -40,7 +39,7 @@ dependencies:
|
|
40
39
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
41
|
requirements:
|
43
|
-
- -
|
42
|
+
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
44
|
version: 1.5.2
|
46
45
|
type: :development
|
@@ -57,6 +56,7 @@ extra_rdoc_files:
|
|
57
56
|
- README.md
|
58
57
|
files:
|
59
58
|
- .document
|
59
|
+
- CHANGES.txt
|
60
60
|
- Gemfile
|
61
61
|
- Gemfile.lock
|
62
62
|
- LICENSE.txt
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- command-builder.gemspec
|
67
67
|
- lib/command-builder.rb
|
68
68
|
- test.rb
|
69
|
-
has_rdoc: true
|
70
69
|
homepage: https://github.com/martinkozak/command-builder
|
71
70
|
licenses:
|
72
71
|
- MIT
|
@@ -80,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
79
|
requirements:
|
81
80
|
- - ">="
|
82
81
|
- !ruby/object:Gem::Version
|
83
|
-
hash:
|
82
|
+
hash: 1643594554722513454
|
84
83
|
segments:
|
85
84
|
- 0
|
86
85
|
version: "0"
|
@@ -93,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
92
|
requirements: []
|
94
93
|
|
95
94
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.5
|
95
|
+
rubygems_version: 1.8.5
|
97
96
|
signing_key:
|
98
97
|
specification_version: 3
|
99
98
|
summary: Builds call to some command runnable from shell command line from its arguments.
|