rprogram 0.1.5 → 0.1.6
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.tar.gz.sig +0 -0
- data/History.txt +14 -0
- data/LICENSE.txt +23 -0
- data/Manifest.txt +17 -4
- data/README.txt +1 -0
- data/Rakefile +6 -5
- data/lib/rprogram/compat.rb +8 -8
- data/lib/rprogram/extensions.rb +0 -2
- data/lib/rprogram/nameable.rb +8 -1
- data/lib/rprogram/non_option.rb +37 -17
- data/lib/rprogram/option.rb +44 -44
- data/lib/rprogram/option_list.rb +4 -6
- data/lib/rprogram/options.rb +5 -5
- data/lib/rprogram/program.rb +13 -14
- data/lib/rprogram/rprogram.rb +2 -2
- data/lib/rprogram/task.rb +37 -33
- data/lib/rprogram/version.rb +1 -1
- data/spec/classes/aliased_program.rb +10 -0
- data/spec/classes/ls_program.rb +8 -0
- data/spec/classes/ls_selinux_task.rb +7 -0
- data/spec/classes/ls_task.rb +12 -0
- data/spec/classes/named_program.rb +9 -0
- data/spec/compat_spec.rb +21 -0
- data/spec/nameable_spec.rb +55 -0
- data/spec/non_option_spec.rb +48 -0
- data/spec/option_examples.rb +17 -0
- data/spec/option_list_spec.rb +25 -0
- data/spec/option_spec.rb +178 -0
- data/spec/program_spec.rb +52 -0
- data/spec/rprogram_spec.rb +18 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/task_spec.rb +85 -0
- metadata +54 -13
- metadata.gz.sig +0 -0
- data/lib/rprogram/extensions/array.rb +0 -7
- data/lib/rprogram/extensions/hash.rb +0 -15
- data/test/test_rprogram.rb +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 0.1.6 / 2009-06-30
|
2
|
+
|
3
|
+
* Use Hoe 2.2.0.
|
4
|
+
* Removed requirement for 'open3'.
|
5
|
+
* Renamed Compat.PATHS to Compat.paths.
|
6
|
+
* Refactored Option#arguments.
|
7
|
+
* Removed Option#format.
|
8
|
+
* Refactored NonOption#arguments.
|
9
|
+
* Renamed NonOption#leading to NonOption#leading?.
|
10
|
+
* Removed NonOption#tailing.
|
11
|
+
* Added NonOption#tailing?.
|
12
|
+
* Added specs.
|
13
|
+
* All specs pass on Ruby 1.9.1-p0 and 1.8.6-p287.
|
14
|
+
|
1
15
|
=== 0.1.5 / 2009-01-14
|
2
16
|
|
3
17
|
* Use Kernel.system in RProgram::Program#run, instead of Open3.popen3:
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
The MIT License
|
4
|
+
|
5
|
+
Copyright (c) 2007-2008 Hal Brodigan
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
THE SOFTWARE.
|
data/Manifest.txt
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
History.txt
|
2
2
|
Manifest.txt
|
3
|
+
LICENSE.txt
|
3
4
|
README.txt
|
4
5
|
Rakefile
|
5
6
|
lib/rprogram.rb
|
6
|
-
lib/rprogram/version.rb
|
7
7
|
lib/rprogram/compat.rb
|
8
8
|
lib/rprogram/exceptions/program_not_found.rb
|
9
9
|
lib/rprogram/exceptions.rb
|
10
10
|
lib/rprogram/extensions/meta/object.rb
|
11
11
|
lib/rprogram/extensions/meta.rb
|
12
|
-
lib/rprogram/extensions/array.rb
|
13
|
-
lib/rprogram/extensions/hash.rb
|
14
12
|
lib/rprogram/extensions.rb
|
15
13
|
lib/rprogram/option_list.rb
|
16
14
|
lib/rprogram/option.rb
|
@@ -20,4 +18,19 @@ lib/rprogram/task.rb
|
|
20
18
|
lib/rprogram/nameable.rb
|
21
19
|
lib/rprogram/program.rb
|
22
20
|
lib/rprogram/rprogram.rb
|
23
|
-
|
21
|
+
lib/rprogram/version.rb
|
22
|
+
spec/spec_helper.rb
|
23
|
+
spec/classes/named_program.rb
|
24
|
+
spec/classes/aliased_program.rb
|
25
|
+
spec/classes/ls_program.rb
|
26
|
+
spec/classes/ls_task.rb
|
27
|
+
spec/classes/ls_selinux_task.rb
|
28
|
+
spec/rprogram_spec.rb
|
29
|
+
spec/compat_spec.rb
|
30
|
+
spec/option_examples.rb
|
31
|
+
spec/option_spec.rb
|
32
|
+
spec/non_option_spec.rb
|
33
|
+
spec/option_list_spec.rb
|
34
|
+
spec/nameable_spec.rb
|
35
|
+
spec/program_spec.rb
|
36
|
+
spec/task_spec.rb
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'hoe'
|
5
|
-
require '
|
5
|
+
require 'hoe/signing'
|
6
|
+
require './tasks/spec.rb'
|
6
7
|
|
7
|
-
Hoe.
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
Hoe.spec('rprogram') do
|
9
|
+
self.rubyforge_name = 'rprogram'
|
10
|
+
self.developer('Postmodern', 'postmodern.mod3@gmail.com')
|
11
|
+
self.remote_rdoc_dir = ''
|
11
12
|
end
|
12
13
|
|
13
14
|
# vim: syntax=Ruby
|
data/lib/rprogram/compat.rb
CHANGED
@@ -5,7 +5,7 @@ module RProgram
|
|
5
5
|
#
|
6
6
|
# Compat.arch #=> "linux"
|
7
7
|
#
|
8
|
-
def
|
8
|
+
def Compat.platform
|
9
9
|
RUBY_PLATFORM.split('-').last
|
10
10
|
end
|
11
11
|
|
@@ -14,14 +14,14 @@ module RProgram
|
|
14
14
|
# If the +PATH+ environment variable is not setup, an empty array will
|
15
15
|
# be returned.
|
16
16
|
#
|
17
|
-
# Compat.
|
17
|
+
# Compat.paths #=> ["/bin", "/usr/bin"]
|
18
18
|
#
|
19
|
-
def
|
19
|
+
def Compat.paths
|
20
20
|
# return an empty array in case
|
21
21
|
# the PATH variable does not exist
|
22
22
|
return [] unless ENV['PATH']
|
23
23
|
|
24
|
-
if
|
24
|
+
if Compat.platform =~ /mswin(32|64)/
|
25
25
|
return ENV['PATH'].split(';')
|
26
26
|
else
|
27
27
|
return ENV['PATH'].split(':')
|
@@ -34,8 +34,8 @@ module RProgram
|
|
34
34
|
#
|
35
35
|
# Compat.find_program('as') #=> "/usr/bin/as"
|
36
36
|
#
|
37
|
-
def
|
38
|
-
|
37
|
+
def Compat.find_program(name)
|
38
|
+
Compat.paths.each do |dir|
|
39
39
|
full_path = File.expand_path(File.join(dir,name))
|
40
40
|
|
41
41
|
return full_path if File.file?(full_path)
|
@@ -51,8 +51,8 @@ module RProgram
|
|
51
51
|
#
|
52
52
|
# Compat.find_program_by_names("gas","as") #=> "/usr/bin/as"
|
53
53
|
#
|
54
|
-
def
|
55
|
-
names.map { |name|
|
54
|
+
def Compat.find_program_by_names(*names)
|
55
|
+
names.map { |name| Compat.find_program(name) }.compact.first
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/lib/rprogram/extensions.rb
CHANGED
data/lib/rprogram/nameable.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rprogram/compat'
|
|
3
3
|
|
4
4
|
module RProgram
|
5
5
|
module Nameable
|
6
|
-
def self.included(base)
|
6
|
+
def self.included(base) # :nodoc:
|
7
7
|
base.metaclass_eval do
|
8
8
|
#
|
9
9
|
# Returns the name of the program.
|
@@ -60,5 +60,12 @@ module RProgram
|
|
60
60
|
def program_aliases
|
61
61
|
self.class.program_aliases
|
62
62
|
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Returns the program names.
|
66
|
+
#
|
67
|
+
def program_names
|
68
|
+
self.class.program_names
|
69
|
+
end
|
63
70
|
end
|
64
71
|
end
|
data/lib/rprogram/non_option.rb
CHANGED
@@ -4,12 +4,6 @@ module RProgram
|
|
4
4
|
# Name of the argument(s)
|
5
5
|
attr_reader :name
|
6
6
|
|
7
|
-
# Is the argument a leading argument(s)
|
8
|
-
attr_reader :leading
|
9
|
-
|
10
|
-
# Is the argument a tailing argument(s)
|
11
|
-
attr_reader :tailing
|
12
|
-
|
13
7
|
# Can the argument be specified multiple times
|
14
8
|
attr_reader :multiple
|
15
9
|
|
@@ -28,9 +22,31 @@ module RProgram
|
|
28
22
|
def initialize(options={})
|
29
23
|
@name = options[:name]
|
30
24
|
|
31
|
-
@
|
32
|
-
|
33
|
-
|
25
|
+
@tailing = if options[:leading]
|
26
|
+
!(options[:leading])
|
27
|
+
elsif options[:tailing]
|
28
|
+
options[:tailing]
|
29
|
+
else
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
@multiple = (options[:multiple] || false)
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Returns +true+ if the non-options arguments are tailing, returns
|
38
|
+
# +false+ otherwise.
|
39
|
+
#
|
40
|
+
def tailing?
|
41
|
+
@tailing == true
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Returns +true+ if the non-options arguments are leading, returns
|
46
|
+
# +false+ otherwise.
|
47
|
+
#
|
48
|
+
def leading?
|
49
|
+
!(@tailing)
|
34
50
|
end
|
35
51
|
|
36
52
|
#
|
@@ -38,19 +54,23 @@ module RProgram
|
|
38
54
|
# specified _value_.
|
39
55
|
#
|
40
56
|
def arguments(value)
|
41
|
-
return []
|
57
|
+
return [] unless value
|
42
58
|
|
43
59
|
if value.kind_of?(Hash)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
60
|
+
value = value.map do |key,sub_value|
|
61
|
+
if sub_value == true
|
62
|
+
key.to_s
|
63
|
+
elsif sub_value
|
64
|
+
"#{key}=#{sub_value}"
|
65
|
+
end
|
50
66
|
end
|
67
|
+
elsif value.kind_of?(Array)
|
68
|
+
value = value.flatten
|
51
69
|
else
|
52
|
-
|
70
|
+
value = [value]
|
53
71
|
end
|
72
|
+
|
73
|
+
return value.compact
|
54
74
|
end
|
55
75
|
|
56
76
|
end
|
data/lib/rprogram/option.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rprogram/extensions'
|
2
|
-
|
3
1
|
module RProgram
|
4
2
|
class Option
|
5
3
|
|
@@ -43,12 +41,26 @@ module RProgram
|
|
43
41
|
def initialize(options={},&block)
|
44
42
|
@flag = options[:flag]
|
45
43
|
|
46
|
-
@equals = options[:equals] || false
|
47
|
-
@multiple = options[:multiple] || false
|
48
|
-
@separator = options[:separator]
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
@equals = (options[:equals] || false)
|
45
|
+
@multiple = (options[:multiple] || false)
|
46
|
+
@separator = if options[:separator]
|
47
|
+
options[:separator]
|
48
|
+
elsif options[:equals]
|
49
|
+
' '
|
50
|
+
end
|
51
|
+
@sub_options = (options[:sub_options] || false)
|
52
|
+
|
53
|
+
@formatter = if block
|
54
|
+
block
|
55
|
+
else
|
56
|
+
Proc.new do |opt,value|
|
57
|
+
if opt.equals
|
58
|
+
["#{opt.flag}=#{value.first}"]
|
59
|
+
else
|
60
|
+
[opt.flag] + value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
66
|
#
|
@@ -56,47 +68,35 @@ module RProgram
|
|
56
68
|
# _value_.
|
57
69
|
#
|
58
70
|
def arguments(value)
|
59
|
-
return [@flag] if value==true
|
60
|
-
return []
|
61
|
-
|
62
|
-
if value.respond_to?(:arguments)
|
63
|
-
|
71
|
+
return [@flag] if value == true
|
72
|
+
return [] unless value
|
73
|
+
|
74
|
+
value = value.arguments if value.respond_to?(:arguments)
|
75
|
+
|
76
|
+
if value.kind_of?(Hash)
|
77
|
+
value = value.map { |key,sub_value|
|
78
|
+
if sub_value == true
|
79
|
+
key.to_s
|
80
|
+
elsif sub_value
|
81
|
+
"#{key}=#{sub_value}"
|
82
|
+
end
|
83
|
+
}
|
84
|
+
elsif value.kind_of?(Array)
|
85
|
+
value.flatten!
|
86
|
+
else
|
87
|
+
value = [value]
|
64
88
|
end
|
65
89
|
|
90
|
+
value.compact!
|
91
|
+
|
66
92
|
if @multiple
|
67
|
-
|
68
|
-
|
93
|
+
return value.inject([]) do |args,value|
|
94
|
+
args + @formatter.call(self,[value])
|
69
95
|
end
|
70
|
-
end
|
71
|
-
|
72
|
-
if (value.kind_of?(Array) && @separator)
|
73
|
-
value = value.join(@separator)
|
74
|
-
end
|
75
|
-
|
76
|
-
return format(value)
|
77
|
-
end
|
78
|
-
|
79
|
-
protected
|
80
|
-
|
81
|
-
#
|
82
|
-
# Returns an Array of the flag and the specified _value_ in argument
|
83
|
-
# form.
|
84
|
-
#
|
85
|
-
def default_format(value)
|
86
|
-
return [@flag] + value if value.kind_of?(Array)
|
87
|
-
return ["#{flag}=#{value}"] if @equals
|
88
|
-
return [@flag, value]
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# Formats specified _value_ with the option flag using
|
93
|
-
# either the custom formating or the default_format.
|
94
|
-
#
|
95
|
-
def format(value)
|
96
|
-
if @formating
|
97
|
-
return @formating.call(@flag,value).to_a
|
98
96
|
else
|
99
|
-
|
97
|
+
value = [value.join(@separator)] if @separator
|
98
|
+
|
99
|
+
return @formatter.call(self,value)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
data/lib/rprogram/option_list.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rprogram/extensions/hash'
|
2
|
-
|
3
1
|
module RProgram
|
4
2
|
class OptionList < Hash
|
5
3
|
|
@@ -23,14 +21,14 @@ module RProgram
|
|
23
21
|
name = sym.to_s
|
24
22
|
|
25
23
|
unless block
|
26
|
-
if (name =~ /=$/ && args.length==1)
|
27
|
-
return self[name.chop.to_sym] = args
|
28
|
-
elsif args.
|
24
|
+
if (name =~ /=$/ && args.length == 1)
|
25
|
+
return self[name.chop.to_sym] = args.first
|
26
|
+
elsif args.empty?
|
29
27
|
return self[sym]
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
super(sym,*args,&block)
|
31
|
+
return super(sym,*args,&block)
|
34
32
|
end
|
35
33
|
|
36
34
|
end
|
data/lib/rprogram/options.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rprogram/option'
|
|
4
4
|
|
5
5
|
module RProgram
|
6
6
|
module Options
|
7
|
-
def self.included(base)
|
7
|
+
def self.included(base) # :nodoc:
|
8
8
|
base.metaclass_eval do
|
9
9
|
#
|
10
10
|
# Returns a Hash of all defined non-options.
|
@@ -21,7 +21,7 @@ module RProgram
|
|
21
21
|
name = name.to_sym
|
22
22
|
|
23
23
|
ancestors.each do |base|
|
24
|
-
if base.include?(Options)
|
24
|
+
if base.include?(RProgram::Options)
|
25
25
|
return true if base.non_options.include?(name)
|
26
26
|
end
|
27
27
|
end
|
@@ -36,7 +36,7 @@ module RProgram
|
|
36
36
|
name = name.to_sym
|
37
37
|
|
38
38
|
ancestors.each do |base|
|
39
|
-
if base.include?(Options)
|
39
|
+
if base.include?(RProgram::Options)
|
40
40
|
if base.non_options.has_key?(name)
|
41
41
|
return base.non_options[name]
|
42
42
|
end
|
@@ -61,7 +61,7 @@ module RProgram
|
|
61
61
|
name = name.to_sym
|
62
62
|
|
63
63
|
ancestors.each do |base|
|
64
|
-
if base.include?(Options)
|
64
|
+
if base.include?(RProgram::Options)
|
65
65
|
return true if base.options.has_key?(name)
|
66
66
|
end
|
67
67
|
end
|
@@ -77,7 +77,7 @@ module RProgram
|
|
77
77
|
name = name.to_sym
|
78
78
|
|
79
79
|
ancestors.each do |base|
|
80
|
-
if base.include?(Options)
|
80
|
+
if base.include?(RProgram::Options)
|
81
81
|
return base.options[name] if base.options.has_key?(name)
|
82
82
|
end
|
83
83
|
end
|
data/lib/rprogram/program.rb
CHANGED
@@ -4,8 +4,6 @@ require 'rprogram/task'
|
|
4
4
|
require 'rprogram/nameable'
|
5
5
|
require 'rprogram/exceptions/program_not_found'
|
6
6
|
|
7
|
-
require 'open3'
|
8
|
-
|
9
7
|
module RProgram
|
10
8
|
class Program
|
11
9
|
|
@@ -39,29 +37,29 @@ module RProgram
|
|
39
37
|
|
40
38
|
#
|
41
39
|
# Creates a new program object with the specified _path_, if _path_
|
42
|
-
# is a valid file. Any given
|
40
|
+
# is a valid file. Any given _arguments_ or a given _block_ will be used
|
43
41
|
# in creating the new program.
|
44
42
|
#
|
45
43
|
# Program.find_with_path('/bin/cd') # => Program
|
46
44
|
#
|
47
45
|
# Program.find_with_path('/obviously/fake') # => nil
|
48
46
|
#
|
49
|
-
def self.find_with_path(path,*
|
50
|
-
return self.new(path,*
|
47
|
+
def self.find_with_path(path,*arguments,&block)
|
48
|
+
return self.new(path,*arguments,&block) if File.file?(path)
|
51
49
|
end
|
52
50
|
|
53
51
|
#
|
54
52
|
# Creates a new program object with the specified _paths_,
|
55
|
-
# if a path within _paths_ is a valid file. Any given
|
53
|
+
# if a path within _paths_ is a valid file. Any given _arguments_ or
|
56
54
|
# a given _block_ will be used in creating the new program.
|
57
55
|
#
|
58
56
|
# Program.find_with_paths(['/bin/cd','/usr/bin/cd']) # => Program
|
59
57
|
#
|
60
58
|
# Program.find_with_paths(['/obviously/fake','/bla']) # => nil
|
61
59
|
#
|
62
|
-
def self.find_with_paths(paths,*
|
60
|
+
def self.find_with_paths(paths,*arguments,&block)
|
63
61
|
paths.each do |path|
|
64
|
-
return self.new(path,*
|
62
|
+
return self.new(path,*arguments,&block) if File.file?(path)
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
@@ -69,7 +67,7 @@ module RProgram
|
|
69
67
|
# Finds and creates the program using it's +program_names+ and returns
|
70
68
|
# a new Program object. If the program cannot be found by any of it's
|
71
69
|
# +program_names+, a ProramNotFound exception will be raised. Any given
|
72
|
-
#
|
70
|
+
# _arguments_ or a given _block_ will be used in creating the new program.
|
73
71
|
#
|
74
72
|
# Program.find # => Program
|
75
73
|
#
|
@@ -77,19 +75,20 @@ module RProgram
|
|
77
75
|
# ...
|
78
76
|
# end
|
79
77
|
#
|
80
|
-
def self.find(*
|
81
|
-
path = Compat.find_program_by_names(program_names)
|
78
|
+
def self.find(*arguments,&block)
|
79
|
+
path = Compat.find_program_by_names(*self.program_names)
|
80
|
+
|
82
81
|
unless path
|
83
|
-
names = program_names.map { |name| name.dump }.join(', ')
|
82
|
+
names = self.program_names.map { |name| name.dump }.join(', ')
|
84
83
|
|
85
84
|
raise(ProgramNotFound,"programs #{names} were not found",caller)
|
86
85
|
end
|
87
86
|
|
88
|
-
return self.new(path,*
|
87
|
+
return self.new(path,*arguments,&block)
|
89
88
|
end
|
90
89
|
|
91
90
|
#
|
92
|
-
# Runs the program with the specified
|
91
|
+
# Runs the program with the specified _arguments_ and returns
|
93
92
|
# either +true+ or +false+, depending on the exit status of the
|
94
93
|
# program.
|
95
94
|
#
|