rprogram 0.1.6 → 0.1.7
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/History.txt +9 -0
- data/Manifest.txt +6 -0
- data/README.txt +4 -0
- data/Rakefile +11 -0
- data/lib/rprogram/compat.rb +21 -9
- data/lib/rprogram/nameable.rb +17 -10
- data/lib/rprogram/non_option.rb +26 -15
- data/lib/rprogram/option.rb +28 -16
- data/lib/rprogram/option_list.rb +4 -1
- data/lib/rprogram/options.rb +33 -17
- data/lib/rprogram/program.rb +86 -21
- data/lib/rprogram/rprogram.rb +6 -4
- data/lib/rprogram/task.rb +109 -48
- data/lib/rprogram/version.rb +2 -1
- data/lib/rprogram/yard/handlers/ruby/legacy/metaclass_eval_handler.rb +21 -0
- data/lib/rprogram/yard/handlers/ruby/legacy.rb +1 -0
- data/lib/rprogram/yard/handlers/ruby/metaclass_eval_handler.rb +18 -0
- data/lib/rprogram/yard/handlers/ruby.rb +2 -0
- data/lib/rprogram/yard/handlers.rb +1 -0
- data/lib/rprogram/yard.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +31 -5
- metadata.gz.sig +0 -0
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.1.7 / 2009-09-21
|
2
|
+
|
3
|
+
* Require Hoe >= 2.3.3.
|
4
|
+
* Require YARD >= 0.2.3.5.
|
5
|
+
* Require RSpec >= 1.2.8.
|
6
|
+
* Use 'hoe/signing' for signed RubyGems.
|
7
|
+
* Moved to YARD based documentation.
|
8
|
+
* All specs pass on JRuby 1.3.1.
|
9
|
+
|
1
10
|
=== 0.1.6 / 2009-06-30
|
2
11
|
|
3
12
|
* Use Hoe 2.2.0.
|
data/Manifest.txt
CHANGED
@@ -19,6 +19,12 @@ lib/rprogram/nameable.rb
|
|
19
19
|
lib/rprogram/program.rb
|
20
20
|
lib/rprogram/rprogram.rb
|
21
21
|
lib/rprogram/version.rb
|
22
|
+
lib/rprogram/yard.rb
|
23
|
+
lib/rprogram/yard/handlers.rb
|
24
|
+
lib/rprogram/yard/handlers/ruby.rb
|
25
|
+
lib/rprogram/yard/handlers/ruby/metaclass_eval_handler.rb
|
26
|
+
lib/rprogram/yard/handlers/ruby/legacy.rb
|
27
|
+
lib/rprogram/yard/handlers/ruby/legacy/metaclass_eval_handler.rb
|
22
28
|
spec/spec_helper.rb
|
23
29
|
spec/classes/named_program.rb
|
24
30
|
spec/classes/aliased_program.rb
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -4,11 +4,22 @@ require 'rubygems'
|
|
4
4
|
require 'hoe'
|
5
5
|
require 'hoe/signing'
|
6
6
|
require './tasks/spec.rb'
|
7
|
+
require './tasks/yard.rb'
|
7
8
|
|
8
9
|
Hoe.spec('rprogram') do
|
9
10
|
self.rubyforge_name = 'rprogram'
|
10
11
|
self.developer('Postmodern', 'postmodern.mod3@gmail.com')
|
11
12
|
self.remote_rdoc_dir = ''
|
13
|
+
|
14
|
+
self.extra_deps = [
|
15
|
+
['yard', '>=0.2.3.5']
|
16
|
+
]
|
17
|
+
|
18
|
+
self.extra_dev_deps = [
|
19
|
+
['rspec', '>=1.2.8']
|
20
|
+
]
|
21
|
+
|
22
|
+
self.spec_extras = {:has_rdoc => 'yard'}
|
12
23
|
end
|
13
24
|
|
14
25
|
# vim: syntax=Ruby
|
data/lib/rprogram/compat.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module RProgram
|
2
2
|
module Compat
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# Determines the native platform.
|
5
5
|
#
|
6
|
+
# @return [String] The native platform.
|
7
|
+
#
|
8
|
+
# @example
|
6
9
|
# Compat.arch #=> "linux"
|
7
10
|
#
|
8
11
|
def Compat.platform
|
@@ -10,10 +13,11 @@ module RProgram
|
|
10
13
|
end
|
11
14
|
|
12
15
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
+
# Determines the contents of the +PATH+ environment variable.
|
17
|
+
#
|
18
|
+
# @return [Array] The contents of the +PATH+ environment variable.
|
16
19
|
#
|
20
|
+
# @example
|
17
21
|
# Compat.paths #=> ["/bin", "/usr/bin"]
|
18
22
|
#
|
19
23
|
def Compat.paths
|
@@ -29,9 +33,13 @@ module RProgram
|
|
29
33
|
end
|
30
34
|
|
31
35
|
#
|
32
|
-
# Finds the
|
33
|
-
#
|
36
|
+
# Finds the full-path of the program with the matching name.
|
37
|
+
#
|
38
|
+
# @param [String] name The name of the program to find.
|
34
39
|
#
|
40
|
+
# @return [String, nil] The full-path of the desired program.
|
41
|
+
#
|
42
|
+
# @example
|
35
43
|
# Compat.find_program('as') #=> "/usr/bin/as"
|
36
44
|
#
|
37
45
|
def Compat.find_program(name)
|
@@ -45,10 +53,14 @@ module RProgram
|
|
45
53
|
end
|
46
54
|
|
47
55
|
#
|
48
|
-
# Finds the program matching one of the names
|
49
|
-
#
|
50
|
-
#
|
56
|
+
# Finds the program matching one of the matching names.
|
57
|
+
#
|
58
|
+
# @param [Array] names The names of the program to use while
|
59
|
+
# searching for the program.
|
60
|
+
#
|
61
|
+
# @return [String, nil] The first full-path for the program.
|
51
62
|
#
|
63
|
+
# @example
|
52
64
|
# Compat.find_program_by_names("gas","as") #=> "/usr/bin/as"
|
53
65
|
#
|
54
66
|
def Compat.find_program_by_names(*names)
|
data/lib/rprogram/nameable.rb
CHANGED
@@ -3,33 +3,37 @@ require 'rprogram/compat'
|
|
3
3
|
|
4
4
|
module RProgram
|
5
5
|
module Nameable
|
6
|
-
def self.included(base)
|
6
|
+
def self.included(base)
|
7
7
|
base.metaclass_eval do
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# @return [String] The name of the program.
|
10
10
|
#
|
11
11
|
def program_name
|
12
12
|
@program_name ||= nil
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# @return [Array] The program's aliases.
|
17
17
|
#
|
18
18
|
def program_aliases
|
19
19
|
@program_aliases ||= []
|
20
20
|
end
|
21
21
|
|
22
22
|
#
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# Combines program_name with program_aliases.
|
24
|
+
#
|
25
|
+
# @return [Array] Names the program is known by.
|
25
26
|
#
|
26
27
|
def program_names
|
27
28
|
([program_name] + program_aliases).compact
|
28
29
|
end
|
29
30
|
|
30
31
|
#
|
31
|
-
# Sets the program name for
|
32
|
+
# Sets the program name for the class.
|
33
|
+
#
|
34
|
+
# @param [String, Symbol] name The new program name.
|
32
35
|
#
|
36
|
+
# @example
|
33
37
|
# name_program 'ls'
|
34
38
|
#
|
35
39
|
def name_program(name)
|
@@ -37,8 +41,11 @@ module RProgram
|
|
37
41
|
end
|
38
42
|
|
39
43
|
#
|
40
|
-
# Sets the program aliases for
|
44
|
+
# Sets the program aliases for the class.
|
45
|
+
#
|
46
|
+
# @param [Array] aliases The new program aliases.
|
41
47
|
#
|
48
|
+
# @example
|
42
49
|
# alias_program 'vim', 'vi'
|
43
50
|
#
|
44
51
|
def alias_program(*aliases)
|
@@ -48,21 +55,21 @@ module RProgram
|
|
48
55
|
end
|
49
56
|
|
50
57
|
#
|
51
|
-
#
|
58
|
+
# @return [String] The program name of the class.
|
52
59
|
#
|
53
60
|
def program_name
|
54
61
|
self.class.program_name
|
55
62
|
end
|
56
63
|
|
57
64
|
#
|
58
|
-
#
|
65
|
+
# @return [Array] The program aliases of the class.
|
59
66
|
#
|
60
67
|
def program_aliases
|
61
68
|
self.class.program_aliases
|
62
69
|
end
|
63
70
|
|
64
71
|
#
|
65
|
-
#
|
72
|
+
# @return [Array] The program names of the class.
|
66
73
|
#
|
67
74
|
def program_names
|
68
75
|
self.class.program_names
|
data/lib/rprogram/non_option.rb
CHANGED
@@ -8,16 +8,19 @@ module RProgram
|
|
8
8
|
attr_reader :multiple
|
9
9
|
|
10
10
|
#
|
11
|
-
# Creates a new NonOption object
|
11
|
+
# Creates a new NonOption object.
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
13
|
+
# @param [Hash] options Additional options.
|
14
|
+
# @option options [Symbol] :name The name of the non-option.
|
15
|
+
# @option options [true, false] :leading (true)
|
16
|
+
# Implies the non-option is a
|
17
|
+
# leading non-option.
|
18
|
+
# @option options [false, true] :tailing (false)
|
19
|
+
# Implies the non-option is a
|
20
|
+
# tailing non-option.
|
21
|
+
# @option options [false, true] :multiple (false)
|
22
|
+
# Implies the non-option maybe
|
23
|
+
# given an Array of values.
|
21
24
|
#
|
22
25
|
def initialize(options={})
|
23
26
|
@name = options[:name]
|
@@ -34,24 +37,32 @@ module RProgram
|
|
34
37
|
end
|
35
38
|
|
36
39
|
#
|
37
|
-
#
|
38
|
-
#
|
40
|
+
# Determines whether the non-option's arguments are tailing.
|
41
|
+
#
|
42
|
+
# @return [true, false] Specifies whether the non-option's arguments are
|
43
|
+
# tailing.
|
39
44
|
#
|
40
45
|
def tailing?
|
41
46
|
@tailing == true
|
42
47
|
end
|
43
48
|
|
44
49
|
#
|
45
|
-
#
|
46
|
-
#
|
50
|
+
# Determines whether the non-option's arguments are leading.
|
51
|
+
#
|
52
|
+
# @return [true, false] Specifies whether the non-option's arguments are
|
53
|
+
# leading.
|
47
54
|
#
|
48
55
|
def leading?
|
49
56
|
!(@tailing)
|
50
57
|
end
|
51
58
|
|
52
59
|
#
|
53
|
-
#
|
54
|
-
#
|
60
|
+
# Formats the arguments for the non-option.
|
61
|
+
#
|
62
|
+
# @param [Hash, Array, String, nil] value The value to use for the
|
63
|
+
# arguments of the non-option.
|
64
|
+
#
|
65
|
+
# @return [Array] The arguments for the non-option.
|
55
66
|
#
|
56
67
|
def arguments(value)
|
57
68
|
return [] unless value
|
data/lib/rprogram/option.rb
CHANGED
@@ -17,26 +17,35 @@ module RProgram
|
|
17
17
|
attr_reader :sub_options
|
18
18
|
|
19
19
|
#
|
20
|
-
# Creates a new Option object with
|
20
|
+
# Creates a new Option object with. If a _block_
|
21
21
|
# is given it will be used for the custom formating of the option. If a
|
22
22
|
# _block_ is not given, the option will use the default_format when
|
23
23
|
# generating the arguments.
|
24
24
|
#
|
25
|
-
#
|
26
|
-
#
|
25
|
+
# @param [Hash] options Additional options.
|
26
|
+
# @option options [String] :flag The command-line flag to use.
|
27
|
+
# @option options [true, false] :equals (false)
|
28
|
+
# Implies the option maybe
|
29
|
+
# formated as
|
30
|
+
# <tt>"--flag=value"</tt>.
|
27
31
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# sub-options. Defaults to false, if not given.
|
32
|
+
# @option options [true, false] :multiple (false)
|
33
|
+
# Specifies the option maybe
|
34
|
+
# given an Array of values.
|
35
|
+
# @option options [String] :separator The separator to use for
|
36
|
+
# formating multiple arguments into
|
37
|
+
# one +String+. Cannot be used with
|
38
|
+
# the +:multiple+ option.
|
39
|
+
# @option options [true, false] :sub_options (false)
|
40
|
+
# Specifies that the option
|
41
|
+
# contains sub-options.
|
39
42
|
#
|
43
|
+
# @yield [option, value] If a block is given, it will be used to format
|
44
|
+
# each value of the option.
|
45
|
+
# @yieldparam [Option] option The option that is being formatted.
|
46
|
+
# @yieldparam [String, Array] value The value to format for the
|
47
|
+
# option. May be an Array, if multiple
|
48
|
+
# values are allowed with the option.
|
40
49
|
#
|
41
50
|
def initialize(options={},&block)
|
42
51
|
@flag = options[:flag]
|
@@ -64,8 +73,11 @@ module RProgram
|
|
64
73
|
end
|
65
74
|
|
66
75
|
#
|
67
|
-
#
|
68
|
-
#
|
76
|
+
# Formats the arguments for the option.
|
77
|
+
#
|
78
|
+
# @param [Hash, Array, String] value The arguments to format.
|
79
|
+
#
|
80
|
+
# @return [Array] The formatted arguments of the option.
|
69
81
|
#
|
70
82
|
def arguments(value)
|
71
83
|
return [@flag] if value == true
|
data/lib/rprogram/option_list.rb
CHANGED
@@ -2,7 +2,9 @@ module RProgram
|
|
2
2
|
class OptionList < Hash
|
3
3
|
|
4
4
|
#
|
5
|
-
# Creates a new OptionList object
|
5
|
+
# Creates a new OptionList object.
|
6
|
+
#
|
7
|
+
# @param [Hash{Symbol => String}] options The options to start with.
|
6
8
|
#
|
7
9
|
def initialize(options={})
|
8
10
|
super(options)
|
@@ -13,6 +15,7 @@ module RProgram
|
|
13
15
|
#
|
14
16
|
# Provides transparent access to the options within the option list.
|
15
17
|
#
|
18
|
+
# @example
|
16
19
|
# opt_list = OptionList.new(:name => 'test')
|
17
20
|
# opt_list.name
|
18
21
|
# # => "test"
|
data/lib/rprogram/options.rb
CHANGED
@@ -4,18 +4,23 @@ require 'rprogram/option'
|
|
4
4
|
|
5
5
|
module RProgram
|
6
6
|
module Options
|
7
|
-
def self.included(base)
|
7
|
+
def self.included(base)
|
8
8
|
base.metaclass_eval do
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# @return [Hash] All defined non-options of the class.
|
11
11
|
#
|
12
12
|
def non_options
|
13
13
|
@non_options ||= {}
|
14
14
|
end
|
15
15
|
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# Searches for the non-option with the matching name in the class
|
18
|
+
# and it's ancestors.
|
19
|
+
#
|
20
|
+
# @param [Symbol, String] name The name to search for.
|
21
|
+
#
|
22
|
+
# @return [true, false] Specifies whether the non-option with the
|
23
|
+
# matching name was defined.
|
19
24
|
#
|
20
25
|
def has_non_option?(name)
|
21
26
|
name = name.to_sym
|
@@ -30,7 +35,12 @@ module RProgram
|
|
30
35
|
end
|
31
36
|
|
32
37
|
#
|
33
|
-
#
|
38
|
+
# Searches for the non-option with the matching name in the class
|
39
|
+
# and it's ancestors.
|
40
|
+
#
|
41
|
+
# @param [Symbol, String] name The name to search for.
|
42
|
+
#
|
43
|
+
# @return [NonOption] The non-option with the matching name.
|
34
44
|
#
|
35
45
|
def get_non_option(name)
|
36
46
|
name = name.to_sym
|
@@ -47,15 +57,20 @@ module RProgram
|
|
47
57
|
end
|
48
58
|
|
49
59
|
#
|
50
|
-
#
|
60
|
+
# @return [Hash] All defined options for the class.
|
51
61
|
#
|
52
62
|
def options
|
53
63
|
@options ||= {}
|
54
64
|
end
|
55
65
|
|
56
66
|
#
|
57
|
-
#
|
58
|
-
#
|
67
|
+
# Searches for the option with the matching name in the class and
|
68
|
+
# it's ancestors.
|
69
|
+
#
|
70
|
+
# @param [Symbol, String] name The name to search for.
|
71
|
+
#
|
72
|
+
# @return [true, false] Specifies whether the option with the
|
73
|
+
# matching name was defined.
|
59
74
|
#
|
60
75
|
def has_option?(name)
|
61
76
|
name = name.to_sym
|
@@ -70,8 +85,12 @@ module RProgram
|
|
70
85
|
end
|
71
86
|
|
72
87
|
#
|
73
|
-
#
|
74
|
-
#
|
88
|
+
# Searches for the option with the matching name in the class and
|
89
|
+
# it's ancestors.
|
90
|
+
#
|
91
|
+
# @param [Symbol, String] name The name to search for.
|
92
|
+
#
|
93
|
+
# @return [Option] The option with the matching name.
|
75
94
|
#
|
76
95
|
def get_option(name)
|
77
96
|
name = name.to_sym
|
@@ -88,31 +107,28 @@ module RProgram
|
|
88
107
|
end
|
89
108
|
|
90
109
|
#
|
91
|
-
#
|
92
|
-
# defined, returns +false+ otherwise.
|
110
|
+
# @see self.has_non_option?
|
93
111
|
#
|
94
112
|
def has_non_option?(name)
|
95
113
|
self.class.has_non_option?(name)
|
96
114
|
end
|
97
115
|
|
98
116
|
#
|
99
|
-
#
|
117
|
+
# @see self.get_non_option
|
100
118
|
#
|
101
119
|
def get_non_option(name)
|
102
120
|
self.class.get_non_option(name)
|
103
121
|
end
|
104
122
|
|
105
123
|
#
|
106
|
-
#
|
107
|
-
# returns +false+ otherwise.
|
124
|
+
# @see self.has_option?
|
108
125
|
#
|
109
126
|
def has_option?(name)
|
110
127
|
self.class.has_option?(name)
|
111
128
|
end
|
112
129
|
|
113
130
|
#
|
114
|
-
#
|
115
|
-
# otherwise.
|
131
|
+
# @see self.get_option
|
116
132
|
#
|
117
133
|
def get_option(name)
|
118
134
|
self.class.get_option(name)
|
data/lib/rprogram/program.rb
CHANGED
@@ -16,10 +16,18 @@ module RProgram
|
|
16
16
|
attr_reader :name
|
17
17
|
|
18
18
|
#
|
19
|
-
# Creates a new Program object
|
20
|
-
# file, a ProgramNotFound exception will be thrown. If a _block_ is
|
21
|
-
# given, it will be passed the newly created Program.
|
19
|
+
# Creates a new Program object.
|
22
20
|
#
|
21
|
+
# @param [String] path The full-path of the program.
|
22
|
+
#
|
23
|
+
# @yield [prog] If a block is given, it will be passed the newly
|
24
|
+
# created Program object.
|
25
|
+
# @yieldparam [Program] prog The newly created program object.
|
26
|
+
#
|
27
|
+
# @raise [ProgramNotFound] Specifies the given path was not a valid
|
28
|
+
# file.
|
29
|
+
#
|
30
|
+
# @example
|
23
31
|
# Program.new('/usr/bin/ls')
|
24
32
|
#
|
25
33
|
def initialize(path,&block)
|
@@ -36,13 +44,27 @@ module RProgram
|
|
36
44
|
end
|
37
45
|
|
38
46
|
#
|
39
|
-
# Creates a new program object
|
40
|
-
#
|
41
|
-
#
|
47
|
+
# Creates a new program object.
|
48
|
+
#
|
49
|
+
# @param [String] path The full-path of the program.
|
50
|
+
# @param [Array] arguments Additional arguments to initialize the
|
51
|
+
# program with.
|
52
|
+
#
|
53
|
+
# @yield [prog] If a block is given, it will be passed the newly
|
54
|
+
# created Program object.
|
55
|
+
# @yieldparam [Program] prog The newly created program object.
|
42
56
|
#
|
43
|
-
#
|
57
|
+
# @return [Program, nil] Returns the newly created Program object.
|
58
|
+
# If the given path was not a valid file,
|
59
|
+
# +nil+ will be returned.
|
44
60
|
#
|
45
|
-
#
|
61
|
+
# @example
|
62
|
+
# Program.find_with_path('/bin/cd')
|
63
|
+
# # => Program
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# Program.find_with_path('/obviously/fake')
|
67
|
+
# # => nil
|
46
68
|
#
|
47
69
|
def self.find_with_path(path,*arguments,&block)
|
48
70
|
return self.new(path,*arguments,&block) if File.file?(path)
|
@@ -53,9 +75,25 @@ module RProgram
|
|
53
75
|
# if a path within _paths_ is a valid file. Any given _arguments_ or
|
54
76
|
# a given _block_ will be used in creating the new program.
|
55
77
|
#
|
56
|
-
#
|
78
|
+
# @param [Array] paths The Array of paths to search for the program.
|
79
|
+
# @param [Array] arguments Additional arguments to initialize
|
80
|
+
# the program with.
|
81
|
+
#
|
82
|
+
# @yield [prog] If a block is given, it will be passed the newly
|
83
|
+
# created Program object.
|
84
|
+
# @yieldparam [Program] prog The newly created program object.
|
85
|
+
#
|
86
|
+
# @return [Program, nil] Returns the newly created Program object.
|
87
|
+
# If none of the given paths were valid files,
|
88
|
+
# +nil+ will be returned.
|
57
89
|
#
|
58
|
-
#
|
90
|
+
# @example
|
91
|
+
# Program.find_with_paths(['/bin/cd','/usr/bin/cd'])
|
92
|
+
# # => Program
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# Program.find_with_paths(['/obviously/fake','/bla'])
|
96
|
+
# # => nil
|
59
97
|
#
|
60
98
|
def self.find_with_paths(paths,*arguments,&block)
|
61
99
|
paths.each do |path|
|
@@ -64,15 +102,27 @@ module RProgram
|
|
64
102
|
end
|
65
103
|
|
66
104
|
#
|
67
|
-
# Finds and creates the program using it's +program_names
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
105
|
+
# Finds and creates the program using it's +program_names+.
|
106
|
+
#
|
107
|
+
# @param [Array] arguments Additional arguments to initialize the
|
108
|
+
# program object with.
|
71
109
|
#
|
72
|
-
#
|
110
|
+
# @yield [prog] If a block is given, it will be passed the newly
|
111
|
+
# created Program object.
|
112
|
+
# @yieldparam [Program] prog The newly created program object.
|
73
113
|
#
|
114
|
+
# @return [Program] The newly created program object.
|
115
|
+
#
|
116
|
+
# @raise [ProgramNotFound] Non of the +program_names+ represented
|
117
|
+
# valid programs on the system.
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# Program.find
|
121
|
+
# # => Program
|
122
|
+
#
|
123
|
+
# @example
|
74
124
|
# MyProgram.find('stuff','here') do |prog|
|
75
|
-
# ...
|
125
|
+
# # ...
|
76
126
|
# end
|
77
127
|
#
|
78
128
|
def self.find(*arguments,&block)
|
@@ -88,15 +138,20 @@ module RProgram
|
|
88
138
|
end
|
89
139
|
|
90
140
|
#
|
91
|
-
# Runs the program
|
92
|
-
#
|
93
|
-
# program.
|
141
|
+
# Runs the program.
|
142
|
+
#
|
143
|
+
# @param [Array] args Addition arguments to run the program with.
|
144
|
+
#
|
145
|
+
# @return [true, false] Specifies the exit status of the program.
|
94
146
|
#
|
147
|
+
# @example
|
95
148
|
# echo = Program.find_by_name('echo')
|
96
149
|
# echo.run('hello')
|
97
150
|
# # hello
|
98
151
|
# # => true
|
99
152
|
#
|
153
|
+
# @see Kernel.system
|
154
|
+
#
|
100
155
|
def run(*args)
|
101
156
|
args = args.map { |arg| arg.to_s }
|
102
157
|
|
@@ -108,15 +163,25 @@ module RProgram
|
|
108
163
|
end
|
109
164
|
|
110
165
|
#
|
111
|
-
# Runs the program with the
|
166
|
+
# Runs the program with the arguments from the given task.
|
167
|
+
#
|
168
|
+
# @param [Task] task The task who's arguments will be used to run the
|
169
|
+
# program.
|
170
|
+
#
|
171
|
+
# @return [true, false] Specifies the exit status of the program.
|
172
|
+
#
|
173
|
+
# @see Kernel.system
|
112
174
|
#
|
113
175
|
def run_task(task)
|
114
176
|
run(*(task.arguments))
|
115
177
|
end
|
116
178
|
|
117
179
|
#
|
118
|
-
#
|
180
|
+
# Converts the program to a String.
|
181
|
+
#
|
182
|
+
# @return [String] The path of the program.
|
119
183
|
#
|
184
|
+
# @example
|
120
185
|
# Program.find_by_name('echo').to_s
|
121
186
|
# # => "/usr/bin/echo"
|
122
187
|
#
|
data/lib/rprogram/rprogram.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module RProgram
|
2
2
|
#
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# @return [true, false] Specifies whether debugging messages are enabled
|
4
|
+
# for RProgram. Defaults to false, if not set.
|
5
5
|
#
|
6
6
|
def RProgram.debug
|
7
7
|
@@rprogram_debug ||= false
|
8
8
|
end
|
9
9
|
|
10
10
|
#
|
11
|
-
# Enables or disables
|
12
|
-
#
|
11
|
+
# Enables or disables debugging messages for RProgram.
|
12
|
+
#
|
13
|
+
# @param [true, false] value The new value of RProgram.debug.
|
14
|
+
# @return [true, false] The new value of RProgram.debug.
|
13
15
|
#
|
14
16
|
def RProgram.debug=(value)
|
15
17
|
@@rprogram_debug = value
|
data/lib/rprogram/task.rb
CHANGED
@@ -7,13 +7,20 @@ module RProgram
|
|
7
7
|
include Options
|
8
8
|
|
9
9
|
#
|
10
|
-
# Creates a new Task object
|
11
|
-
# given, it is passed the newly created Task object.
|
10
|
+
# Creates a new Task object.
|
12
11
|
#
|
12
|
+
# @param [Hash{Symbol => Object}] options Additional task options.
|
13
|
+
#
|
14
|
+
# @yield [task] If a block is given, it will be passed the newly
|
15
|
+
# created task.
|
16
|
+
# @yieldparam [Task] task The newly created Task object.
|
17
|
+
#
|
18
|
+
# @example
|
13
19
|
# Task.new(:test => 'example', :count => 2, :verbose => true)
|
14
20
|
#
|
21
|
+
# @example
|
15
22
|
# Task.new(:help => true) do |task|
|
16
|
-
# ...
|
23
|
+
# # ...
|
17
24
|
# end
|
18
25
|
#
|
19
26
|
def initialize(options={},&block)
|
@@ -24,23 +31,37 @@ module RProgram
|
|
24
31
|
end
|
25
32
|
|
26
33
|
#
|
27
|
-
#
|
28
|
-
#
|
34
|
+
# Creates a new Task object, then formats command-line arguments
|
35
|
+
# using the Task object.
|
36
|
+
#
|
37
|
+
# @param [Hash{Symbol => Object}] options Additional task options.
|
38
|
+
#
|
39
|
+
# @yield [task] If a block is given, it will be passed the newly
|
40
|
+
# created task.
|
41
|
+
# @yieldparam [Task] task The newly created Task object.
|
29
42
|
#
|
43
|
+
# @return [Array] The formatted arguments from a Task object.
|
44
|
+
#
|
45
|
+
# @example
|
30
46
|
# MyTask.arguments(:verbose => true, :count => 2)
|
47
|
+
# # => [...]
|
31
48
|
#
|
49
|
+
# @example
|
32
50
|
# MyTask.arguments do |task|
|
33
51
|
# task.verbose = true
|
34
52
|
# task.file = 'output.txt'
|
35
53
|
# end
|
54
|
+
# # => [...]
|
36
55
|
#
|
37
56
|
def self.arguments(options={},&block)
|
38
57
|
self.new(options,&block).arguments
|
39
58
|
end
|
40
59
|
|
41
60
|
#
|
42
|
-
#
|
43
|
-
#
|
61
|
+
# Generates the command-line arguments for all leading non-options.
|
62
|
+
#
|
63
|
+
# @return [Array] The command-line arguments generated from all the
|
64
|
+
# leading non-options of the task and it's sub-tasks.
|
44
65
|
#
|
45
66
|
def leading_non_options
|
46
67
|
args = []
|
@@ -63,8 +84,10 @@ module RProgram
|
|
63
84
|
end
|
64
85
|
|
65
86
|
#
|
66
|
-
#
|
67
|
-
#
|
87
|
+
# Generates the command-line arguments from all options.
|
88
|
+
#
|
89
|
+
# @return [Array] The command-line arguments generated from all the
|
90
|
+
# options of the task and it's sub-tasks.
|
68
91
|
#
|
69
92
|
def options
|
70
93
|
args = []
|
@@ -84,8 +107,10 @@ module RProgram
|
|
84
107
|
end
|
85
108
|
|
86
109
|
#
|
87
|
-
#
|
88
|
-
#
|
110
|
+
# Generates the command-line arguments from all tailing non-options.
|
111
|
+
#
|
112
|
+
# @return [Array] The command-line arguments generated from all the
|
113
|
+
# tailing non-options of the task and it's sub-tasks.
|
89
114
|
#
|
90
115
|
def tailing_non_options
|
91
116
|
args = []
|
@@ -108,8 +133,11 @@ module RProgram
|
|
108
133
|
end
|
109
134
|
|
110
135
|
#
|
111
|
-
#
|
112
|
-
#
|
136
|
+
# Generates the command-line arguments from the task.
|
137
|
+
#
|
138
|
+
# @return [Array] The command-line arguments compiled from the
|
139
|
+
# leading non-options, options and tailing non-options
|
140
|
+
# of the task and it's sub-tasks.
|
113
141
|
#
|
114
142
|
def arguments
|
115
143
|
leading_non_options + options + tailing_non_options
|
@@ -118,8 +146,12 @@ module RProgram
|
|
118
146
|
protected
|
119
147
|
|
120
148
|
#
|
121
|
-
# Defines a sub-task
|
149
|
+
# Defines a sub-task.
|
150
|
+
#
|
151
|
+
# @param [String, Symbol] name The name of the sub-task.
|
152
|
+
# @param [Task] task The task class of the sub-task.
|
122
153
|
#
|
154
|
+
# @example
|
123
155
|
# subtask :extra, ExtraTask
|
124
156
|
#
|
125
157
|
def self.subtask(name,task)
|
@@ -141,10 +173,24 @@ module RProgram
|
|
141
173
|
end
|
142
174
|
|
143
175
|
#
|
144
|
-
# Defines a non-option
|
176
|
+
# Defines a non-option.
|
145
177
|
#
|
178
|
+
# @param [Hash] options Additional options for the non-option.
|
179
|
+
# @option options [Symbol] :name The name of the non-option.
|
180
|
+
# @option options [true, false] :leading (true)
|
181
|
+
# Implies the non-option is a
|
182
|
+
# leading non-option.
|
183
|
+
# @option options [false, true] :tailing (false)
|
184
|
+
# Implies the non-option is a
|
185
|
+
# tailing non-option.
|
186
|
+
# @option options [false, true] :multiple (false)
|
187
|
+
# Implies the non-option maybe
|
188
|
+
# given an Array of values.
|
189
|
+
#
|
190
|
+
# @example
|
146
191
|
# non_option :name => 'input_file', :tailing => true
|
147
192
|
#
|
193
|
+
# @example
|
148
194
|
# non_option :name => 'file', :tailing => true, :multiple => true
|
149
195
|
#
|
150
196
|
def self.non_option(options={})
|
@@ -166,22 +212,26 @@ module RProgram
|
|
166
212
|
end
|
167
213
|
|
168
214
|
#
|
169
|
-
# Defines a long-option
|
170
|
-
#
|
171
|
-
# _options_ must contain the following keys:
|
172
|
-
# <tt>:flag</tt>:: The flag to use for the option.
|
215
|
+
# Defines a long-option.
|
173
216
|
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
217
|
+
# @param [Hash] options Additional options of the long-option.
|
218
|
+
# @option options [String] :flag The flag to use for the option.
|
219
|
+
# @option options [Symbol] :name The name of the option. Defaults to
|
220
|
+
# the flag_namify'ed form of
|
221
|
+
# <tt>options[:flag]</tt>, if not given.
|
222
|
+
# @option options [true, false] :multiply (false)
|
223
|
+
# Specifies that the option may
|
224
|
+
# appear multiple times in the
|
225
|
+
# arguments.
|
226
|
+
# @option options [true, false] :sub_options (false)
|
227
|
+
# Specifies that the option
|
228
|
+
# contains multiple
|
229
|
+
# sub-options.
|
182
230
|
#
|
231
|
+
# @example
|
183
232
|
# long_option :flag => '--output'
|
184
233
|
#
|
234
|
+
# @example
|
185
235
|
# long_option :flag => '-f', :name => :file
|
186
236
|
#
|
187
237
|
def self.long_option(options={},&block)
|
@@ -193,18 +243,21 @@ module RProgram
|
|
193
243
|
end
|
194
244
|
|
195
245
|
#
|
196
|
-
# Defines a short_option
|
246
|
+
# Defines a short_option.
|
197
247
|
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
248
|
+
# @param [Hash] options Additional options for the short-option.
|
249
|
+
# @option options [Symbol, String] :name The name of the short-option.
|
250
|
+
# @option options [String] :flag The flag to use for the short-option.
|
251
|
+
# @option options [true, false] :multiply (false)
|
252
|
+
# Specifies that the option may
|
253
|
+
# appear multiple times in the
|
254
|
+
# arguments.
|
255
|
+
# @option options [true, false] :sub_options (false)
|
256
|
+
# Specifies that the option
|
257
|
+
# contains multiple
|
258
|
+
# sub-options.
|
207
259
|
#
|
260
|
+
# @example
|
208
261
|
# short_option :flag => '-c', :name => :count
|
209
262
|
#
|
210
263
|
def self.short_option(options,&block)
|
@@ -212,17 +265,19 @@ module RProgram
|
|
212
265
|
end
|
213
266
|
|
214
267
|
#
|
215
|
-
# Defines an option
|
216
|
-
#
|
217
|
-
# _options_ must contain the following keys:
|
218
|
-
# <tt>:name</tt>:: The name of the option.
|
219
|
-
# <tt>:flag</tt>:: The flag to use for the option.
|
268
|
+
# Defines an option.
|
220
269
|
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
270
|
+
# @param [Hash] options Additional options.
|
271
|
+
# @option options [Symbol, String] :name The name of the option.
|
272
|
+
# @option options [String] :flag The flag to use for the option.
|
273
|
+
# @option options [true, false] :multiple (false)
|
274
|
+
# Specifies that the option may
|
275
|
+
# appear multiple times in the
|
276
|
+
# arguments.
|
277
|
+
# @option options [true, false] :sub_options (false)
|
278
|
+
# Specifies that the option
|
279
|
+
# contains multiple
|
280
|
+
# sub-options.
|
226
281
|
#
|
227
282
|
def self.define_option(options,&block)
|
228
283
|
method_name = options[:name].to_sym
|
@@ -250,8 +305,14 @@ module RProgram
|
|
250
305
|
|
251
306
|
#
|
252
307
|
# Converts a long-option flag to a Ruby method name.
|
308
|
+
#
|
309
|
+
# @param [String] flag The command-line flag to convert.
|
310
|
+
#
|
311
|
+
# @return [String] A method-name compatible version of the given flag.
|
253
312
|
#
|
254
|
-
#
|
313
|
+
# @example
|
314
|
+
# Task.flag_namify('--output-file')
|
315
|
+
# # => "output_file"
|
255
316
|
#
|
256
317
|
def Task.flag_namify(flag)
|
257
318
|
flag = flag.to_s.downcase
|
data/lib/rprogram/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'yard/handlers/ruby/legacy/base'
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module Ruby
|
6
|
+
module Legacy
|
7
|
+
class MetaclassEvalHandler < Base
|
8
|
+
|
9
|
+
handles /(\A|\.)metaclass_eval(\s+|\()/
|
10
|
+
|
11
|
+
def process
|
12
|
+
if statement.block
|
13
|
+
parse_block(:namespace => namespace, :scope => :class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rprogram/yard/handlers/ruby/legacy/metaclass_eval_handler'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'yard'
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Handlers
|
5
|
+
module Ruby
|
6
|
+
class MetaclassEvalHandler < YARD::Handlers::Ruby::Base
|
7
|
+
|
8
|
+
handles method_call(:metaclass_eval)
|
9
|
+
|
10
|
+
def process
|
11
|
+
if (block = statement.jump(:brace_block, :do_block).last)
|
12
|
+
parse_block(block, :namespace => namespace, :scope => :class)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rprogram/yard/handlers/ruby'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rprogram/yard/handlers'
|
data/spec/spec_helper.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rprogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
@@ -30,9 +30,29 @@ cert_chain:
|
|
30
30
|
pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-
|
33
|
+
date: 2009-09-25 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.2.3.5
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.8
|
55
|
+
version:
|
36
56
|
- !ruby/object:Gem::Dependency
|
37
57
|
name: hoe
|
38
58
|
type: :development
|
@@ -41,7 +61,7 @@ dependencies:
|
|
41
61
|
requirements:
|
42
62
|
- - ">="
|
43
63
|
- !ruby/object:Gem::Version
|
44
|
-
version: 2.
|
64
|
+
version: 2.3.3
|
45
65
|
version:
|
46
66
|
description: |-
|
47
67
|
RProgram is a library for creating wrappers around command-line programs.
|
@@ -81,6 +101,12 @@ files:
|
|
81
101
|
- lib/rprogram/program.rb
|
82
102
|
- lib/rprogram/rprogram.rb
|
83
103
|
- lib/rprogram/version.rb
|
104
|
+
- lib/rprogram/yard.rb
|
105
|
+
- lib/rprogram/yard/handlers.rb
|
106
|
+
- lib/rprogram/yard/handlers/ruby.rb
|
107
|
+
- lib/rprogram/yard/handlers/ruby/metaclass_eval_handler.rb
|
108
|
+
- lib/rprogram/yard/handlers/ruby/legacy.rb
|
109
|
+
- lib/rprogram/yard/handlers/ruby/legacy/metaclass_eval_handler.rb
|
84
110
|
- spec/spec_helper.rb
|
85
111
|
- spec/classes/named_program.rb
|
86
112
|
- spec/classes/aliased_program.rb
|
@@ -96,7 +122,7 @@ files:
|
|
96
122
|
- spec/nameable_spec.rb
|
97
123
|
- spec/program_spec.rb
|
98
124
|
- spec/task_spec.rb
|
99
|
-
has_rdoc:
|
125
|
+
has_rdoc: yard
|
100
126
|
homepage: http://rprogram.rubyforge.org/
|
101
127
|
licenses: []
|
102
128
|
|
@@ -121,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
147
|
requirements: []
|
122
148
|
|
123
149
|
rubyforge_project: rprogram
|
124
|
-
rubygems_version: 1.3.
|
150
|
+
rubygems_version: 1.3.5
|
125
151
|
signing_key:
|
126
152
|
specification_version: 3
|
127
153
|
summary: RProgram is a library for creating wrappers around command-line programs
|
metadata.gz.sig
CHANGED
Binary file
|