quickl 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +21 -1
- data/Gemfile +17 -1
- data/Gemfile.lock +0 -7
- data/lib/quickl.rb +8 -7
- data/lib/quickl/command.rb +2 -144
- data/lib/quickl/command/builder.rb +20 -17
- data/lib/quickl/command/class_methods.rb +118 -0
- data/lib/quickl/command/delegator.rb +1 -1
- data/lib/quickl/command/instance_methods.rb +12 -0
- data/lib/quickl/command/single.rb +2 -2
- data/lib/quickl/version.rb +1 -1
- data/quickl.gemspec +0 -1
- data/quickl.noespec +10 -12
- data/spec/command/test_command_building.rb +5 -0
- data/spec/mini_client.rb +7 -3
- data/spec/quickl/test_split_commandline_args.rb +9 -0
- data/tasks/spec_test.rake +1 -1
- data/tasks/unit_test.rake +3 -3
- metadata +62 -116
- data/lib/quickl/command/robustness.rb +0 -22
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
+
# 0.4.0 / 2011-08-15
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* The hard-coded way of extracting command documentation as source rdoc has
|
6
|
+
been replaced by a Command.doc_extractor (a Proc) which can be installed
|
7
|
+
through the command builder (advanced usage). Default behavior is kept
|
8
|
+
unchanged, though.
|
9
|
+
* Command.documentation now takes an optional Hash of options, which is passed
|
10
|
+
as second argument to the documentation extractor (the first one being the
|
11
|
+
command class itself).
|
12
|
+
* Quickl.split_commandline_args now accepts the separator on which splitting
|
13
|
+
occurs as second argument.
|
14
|
+
|
15
|
+
* Breaking changes
|
16
|
+
|
17
|
+
* Command#method_missing and well as the Robustness module have been removed
|
18
|
+
after deprecation.
|
19
|
+
* Command.doc_place and Command.doc_src have been removed as well.
|
20
|
+
|
1
21
|
# 0.3.0 / 2011-07-29
|
2
22
|
|
3
23
|
* Upgrading from 0.2.x
|
4
24
|
|
5
25
|
This release is mostly compatible with the 0.2.x branch, but may require a few
|
6
26
|
changes to your code to avoid deprecation warnings and prepare for 0.4.0 that
|
7
|
-
will break if
|
27
|
+
will break if you don't. From the most to the less likely:
|
8
28
|
|
9
29
|
* If you originally copied the Help command from examples, please do it again
|
10
30
|
on the new version. The execute method of Help should be:
|
data/Gemfile
CHANGED
@@ -1,2 +1,18 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
|
-
|
2
|
+
|
3
|
+
group :test do
|
4
|
+
gem "rake", "~> 0.9.2"
|
5
|
+
gem "rspec", "~> 2.6.0"
|
6
|
+
end
|
7
|
+
|
8
|
+
group :release do
|
9
|
+
gem "rake", "~> 0.9.2"
|
10
|
+
gem "rspec", "~> 2.6.0"
|
11
|
+
gem "wlang", "~> 0.10.2"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :doc do
|
15
|
+
gem "yard", "~> 0.7.2"
|
16
|
+
gem "bluecloth", "~> 2.1.0"
|
17
|
+
end
|
18
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
quickl (0.3.0)
|
5
|
-
|
6
1
|
GEM
|
7
2
|
remote: http://rubygems.org/
|
8
3
|
specs:
|
@@ -26,8 +21,6 @@ PLATFORMS
|
|
26
21
|
|
27
22
|
DEPENDENCIES
|
28
23
|
bluecloth (~> 2.1.0)
|
29
|
-
bundler (~> 1.0)
|
30
|
-
quickl!
|
31
24
|
rake (~> 0.9.2)
|
32
25
|
rspec (~> 2.6.0)
|
33
26
|
wlang (~> 0.10.2)
|
data/lib/quickl.rb
CHANGED
@@ -124,15 +124,15 @@ module Quickl
|
|
124
124
|
#
|
125
125
|
# Convenient method for <code>command_class(cmd).documentation</code>
|
126
126
|
#
|
127
|
-
def self.documentation(cmd)
|
128
|
-
command_class(cmd).documentation
|
127
|
+
def self.documentation(cmd, opts = {})
|
128
|
+
command_class(cmd).documentation(opts)
|
129
129
|
end
|
130
130
|
|
131
131
|
#
|
132
132
|
# Alias for documentation
|
133
133
|
#
|
134
|
-
def self.help(cmd)
|
135
|
-
command_class(cmd).help
|
134
|
+
def self.help(cmd, opts = {})
|
135
|
+
command_class(cmd).help(opts)
|
136
136
|
end
|
137
137
|
|
138
138
|
#
|
@@ -186,13 +186,14 @@ module Quickl
|
|
186
186
|
end
|
187
187
|
|
188
188
|
#
|
189
|
-
# Splits an array `args`
|
189
|
+
# Splits an array `args` a separator, the option separator
|
190
|
+
# '--' by default.
|
190
191
|
#
|
191
|
-
def self.split_commandline_args(args)
|
192
|
+
def self.split_commandline_args(args, separator = '--')
|
192
193
|
args = args.dup
|
193
194
|
result, current = [], []
|
194
195
|
until args.empty?
|
195
|
-
if (x = args.shift) ==
|
196
|
+
if (x = args.shift) == separator
|
196
197
|
result << current
|
197
198
|
current = []
|
198
199
|
else
|
data/lib/quickl/command.rb
CHANGED
@@ -1,151 +1,10 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'quickl/command/class_methods'
|
3
|
+
require 'quickl/command/instance_methods'
|
2
4
|
module Quickl
|
3
5
|
class Command
|
4
6
|
extend Naming
|
5
7
|
|
6
|
-
# Methods installed on all command classes
|
7
|
-
module ClassMethods
|
8
|
-
|
9
|
-
# The super command, if any
|
10
|
-
attr_accessor :super_command
|
11
|
-
|
12
|
-
# Command's summary
|
13
|
-
attr_accessor :doc_place
|
14
|
-
|
15
|
-
# Returns the array of defined subcommands
|
16
|
-
def subcommands
|
17
|
-
@subcommands ||= []
|
18
|
-
end
|
19
|
-
|
20
|
-
# Returns a subcommand by its name, or nil
|
21
|
-
def subcommand_by_name(name)
|
22
|
-
return nil unless has_sub_commands?
|
23
|
-
look = name.split(':')
|
24
|
-
found = subcommands.find{|cmd| cmd.command_name == look.first}
|
25
|
-
if found.nil? or (look.size == 1)
|
26
|
-
return found
|
27
|
-
else
|
28
|
-
found.subcommand_by_name(look[1..-1].join(':'))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns true if this command has at least one
|
33
|
-
# subcommand
|
34
|
-
def has_sub_commands?
|
35
|
-
@subcommands and !@subcommands.empty?
|
36
|
-
end
|
37
|
-
|
38
|
-
############################################### Textual information about the command
|
39
|
-
|
40
|
-
# Returns name of the program under execution
|
41
|
-
def program_name
|
42
|
-
Quickl.program_name
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns command name
|
46
|
-
def command_name
|
47
|
-
module2command(self)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Loads and returns the documentation source
|
51
|
-
def doc_src
|
52
|
-
@doc_src ||= unless doc_place
|
53
|
-
"no documentation available"
|
54
|
-
else
|
55
|
-
file, line = doc_place
|
56
|
-
RubyTools::extract_file_rdoc(file, line, true)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns command documentation
|
61
|
-
def documentation
|
62
|
-
@documentation ||= instance_eval("%Q{#{doc_src}}", *doc_place)
|
63
|
-
end
|
64
|
-
alias :help :documentation
|
65
|
-
|
66
|
-
# Returns command usage
|
67
|
-
def usage
|
68
|
-
doc = documentation.split("\n")
|
69
|
-
doc.each_with_index{|line,i|
|
70
|
-
case line
|
71
|
-
when /Usage:/
|
72
|
-
return line.strip
|
73
|
-
when /SYNOPSIS/
|
74
|
-
return doc[i+1].strip || "no usage available"
|
75
|
-
end
|
76
|
-
}
|
77
|
-
"no usage available"
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns command overview
|
81
|
-
def overview
|
82
|
-
doc = documentation.split("\n")
|
83
|
-
doc.find{|s| !s.strip.empty?} || "no overview available"
|
84
|
-
end
|
85
|
-
|
86
|
-
# Runs the command
|
87
|
-
def run(argv = [], requester = nil)
|
88
|
-
cmd = self.new
|
89
|
-
cmd.run(argv, requester)
|
90
|
-
rescue Quickl::Error => ex
|
91
|
-
handle_error(ex, cmd)
|
92
|
-
end
|
93
|
-
|
94
|
-
############################################### Error handling
|
95
|
-
|
96
|
-
# Bypass reaction to some exceptions
|
97
|
-
def no_react_to(*args)
|
98
|
-
@no_react_to ||= []
|
99
|
-
@no_react_to += args
|
100
|
-
end
|
101
|
-
|
102
|
-
# Should I bypass reaction to a given error?
|
103
|
-
def no_react_to?(ex)
|
104
|
-
defined?(@no_react_to) && Array(@no_react_to).find{|c|
|
105
|
-
ex.is_a?(c)
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
# Should I react to a given error?
|
110
|
-
def react_to?(ex)
|
111
|
-
!no_react_to?(ex)
|
112
|
-
end
|
113
|
-
|
114
|
-
# Handles a command error
|
115
|
-
def handle_error(ex, cmd = self)
|
116
|
-
if react_to?(ex)
|
117
|
-
begin
|
118
|
-
ex.command = cmd
|
119
|
-
ex.react!
|
120
|
-
rescue Quickl::Error => ex2
|
121
|
-
handle_error(ex2, cmd)
|
122
|
-
end
|
123
|
-
else
|
124
|
-
raise ex
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
end # module ClassMethods
|
129
|
-
|
130
|
-
# Methods installed on all command instances
|
131
|
-
module InstanceMethods
|
132
|
-
|
133
|
-
# Who is requesting command execution?
|
134
|
-
attr_reader :requester
|
135
|
-
|
136
|
-
# Delegate unrecognized calls to the command class
|
137
|
-
# (gives access to options, help, usage, ...)
|
138
|
-
def method_missing(name, *args, &block)
|
139
|
-
if self.class.respond_to?(name)
|
140
|
-
Quickl.deprecated(name, "self.class.#{name}", caller)
|
141
|
-
self.class.send(name, *args, &block)
|
142
|
-
else
|
143
|
-
super
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
end # module InstanceMethods
|
148
|
-
|
149
8
|
# Tracks child classes
|
150
9
|
def self.inherited(command)
|
151
10
|
Quickl.build_command(command)
|
@@ -154,7 +13,6 @@ module Quickl
|
|
154
13
|
end # class Command
|
155
14
|
end # module Quickl
|
156
15
|
require 'quickl/command/builder'
|
157
|
-
require 'quickl/command/robustness'
|
158
16
|
require 'quickl/command/options'
|
159
17
|
require 'quickl/command/single'
|
160
18
|
require 'quickl/command/delegator'
|
@@ -2,11 +2,21 @@ module Quickl
|
|
2
2
|
class Command
|
3
3
|
class Builder
|
4
4
|
|
5
|
-
#
|
5
|
+
# The super command, if any
|
6
|
+
attr_accessor :super_command
|
7
|
+
alias :"command_parent=" :"super_command="
|
8
|
+
|
9
|
+
# Extractor for documentation
|
10
|
+
attr_accessor :doc_extractor
|
11
|
+
|
12
|
+
# Sets place of the documentation
|
6
13
|
def document(file, line)
|
7
|
-
@
|
14
|
+
@doc_extractor = lambda{|cmd, opts|
|
15
|
+
text = RubyTools::extract_file_rdoc(file, line, true)
|
16
|
+
cmd.instance_eval("%Q{#{text}}", file, line)
|
17
|
+
}
|
8
18
|
end
|
9
|
-
|
19
|
+
|
10
20
|
# Adds some command class modules
|
11
21
|
def class_modules(*mods)
|
12
22
|
@class_modules ||= [
|
@@ -21,18 +31,12 @@ module Quickl
|
|
21
31
|
def instance_modules(*mods)
|
22
32
|
@instance_modules ||= [
|
23
33
|
Command::InstanceMethods,
|
24
|
-
Command::Robustness,
|
25
34
|
Command::Options::InstanceMethods
|
26
35
|
]
|
27
36
|
@instance_modules += mods
|
28
37
|
end
|
29
38
|
alias :instance_module instance_modules
|
30
39
|
|
31
|
-
# Sets the parent of the command currently built
|
32
|
-
def command_parent=(p)
|
33
|
-
@parent = p
|
34
|
-
end
|
35
|
-
|
36
40
|
# Installs a callback block to execute at
|
37
41
|
# install time
|
38
42
|
def callback(&block)
|
@@ -51,15 +55,14 @@ module Quickl
|
|
51
55
|
}
|
52
56
|
|
53
57
|
# install documentation
|
54
|
-
|
55
|
-
|
56
|
-
end
|
58
|
+
self.doc_extractor ||= lambda{|cmd, opts| "no documentation available for #{cmd}" }
|
59
|
+
command.doc_extractor = doc_extractor
|
57
60
|
|
58
61
|
# install hierarchy
|
59
|
-
|
60
|
-
if
|
61
|
-
command.super_command =
|
62
|
-
|
62
|
+
self.super_command ||= RubyTools::parent_module(command)
|
63
|
+
if super_command && super_command.ancestors.include?(Command)
|
64
|
+
command.super_command = super_command
|
65
|
+
super_command.subcommands << command
|
63
66
|
end
|
64
67
|
|
65
68
|
# execute callbacks
|
@@ -72,4 +75,4 @@ module Quickl
|
|
72
75
|
|
73
76
|
end # class Builder
|
74
77
|
end # class Command
|
75
|
-
end # module Quickl
|
78
|
+
end # module Quickl
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
module Quickl
|
3
|
+
class Command
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
# The super command, if any
|
7
|
+
attr_accessor :super_command
|
8
|
+
|
9
|
+
# Extractor for documentation
|
10
|
+
attr_accessor :doc_extractor
|
11
|
+
|
12
|
+
# Returns the array of defined subcommands
|
13
|
+
def subcommands
|
14
|
+
@subcommands ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns a subcommand by its name, or nil
|
18
|
+
def subcommand_by_name(name)
|
19
|
+
return nil unless has_sub_commands?
|
20
|
+
look = name.split(':')
|
21
|
+
found = subcommands.find{|cmd| cmd.command_name == look.first}
|
22
|
+
if found.nil? or (look.size == 1)
|
23
|
+
return found
|
24
|
+
else
|
25
|
+
found.subcommand_by_name(look[1..-1].join(':'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns true if this command has at least one
|
30
|
+
# subcommand
|
31
|
+
def has_sub_commands?
|
32
|
+
@subcommands and !@subcommands.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
############################################### Textual information about the command
|
36
|
+
|
37
|
+
# Returns name of the program under execution
|
38
|
+
def program_name
|
39
|
+
Quickl.program_name
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns command name
|
43
|
+
def command_name
|
44
|
+
module2command(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns command documentation
|
48
|
+
def documentation(opts = {})
|
49
|
+
doc_extractor.call(self, opts)
|
50
|
+
end
|
51
|
+
alias :help :documentation
|
52
|
+
|
53
|
+
# Returns command usage
|
54
|
+
def usage
|
55
|
+
doc = documentation.split("\n")
|
56
|
+
doc.each_with_index{|line,i|
|
57
|
+
case line
|
58
|
+
when /Usage:/
|
59
|
+
return line.strip
|
60
|
+
when /SYNOPSIS/
|
61
|
+
return doc[i+1].strip || "no usage available"
|
62
|
+
end
|
63
|
+
}
|
64
|
+
"no usage available"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns command overview
|
68
|
+
def overview
|
69
|
+
doc = documentation.split("\n")
|
70
|
+
doc.find{|s| !s.strip.empty?} || "no overview available"
|
71
|
+
end
|
72
|
+
|
73
|
+
# Runs the command
|
74
|
+
def run(argv = [], requester = nil)
|
75
|
+
cmd = self.new
|
76
|
+
cmd.run(argv, requester)
|
77
|
+
rescue Quickl::Error => ex
|
78
|
+
handle_error(ex, cmd)
|
79
|
+
end
|
80
|
+
|
81
|
+
############################################### Error handling
|
82
|
+
|
83
|
+
# Bypass reaction to some exceptions
|
84
|
+
def no_react_to(*args)
|
85
|
+
@no_react_to ||= []
|
86
|
+
@no_react_to += args
|
87
|
+
end
|
88
|
+
|
89
|
+
# Should I bypass reaction to a given error?
|
90
|
+
def no_react_to?(ex)
|
91
|
+
defined?(@no_react_to) && Array(@no_react_to).find{|c|
|
92
|
+
ex.is_a?(c)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
# Should I react to a given error?
|
97
|
+
def react_to?(ex)
|
98
|
+
!no_react_to?(ex)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Handles a command error
|
102
|
+
def handle_error(ex, cmd = self)
|
103
|
+
if react_to?(ex)
|
104
|
+
begin
|
105
|
+
ex.command = cmd
|
106
|
+
ex.react!
|
107
|
+
rescue Quickl::Error => ex2
|
108
|
+
handle_error(ex2, cmd)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
raise ex
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end # module ClassMethods
|
116
|
+
end # class Command
|
117
|
+
end # module Quickl
|
118
|
+
|
@@ -55,7 +55,7 @@ module Quickl
|
|
55
55
|
#
|
56
56
|
def self.Delegator(*args)
|
57
57
|
command_builder do |b|
|
58
|
-
b.document(*args)
|
58
|
+
b.document(*args) unless args.empty?
|
59
59
|
b.class_module(Command::Delegator::ClassMethods)
|
60
60
|
b.instance_module(Command::Delegator::InstanceMethods)
|
61
61
|
yield(b) if block_given?
|
@@ -16,11 +16,11 @@ module Quickl
|
|
16
16
|
#
|
17
17
|
def self.Command(*args)
|
18
18
|
command_builder do |b|
|
19
|
-
b.document(*args)
|
19
|
+
b.document(*args) unless args.empty?
|
20
20
|
b.instance_module(Command::Single)
|
21
21
|
yield(b) if block_given?
|
22
22
|
end
|
23
23
|
Command
|
24
24
|
end
|
25
25
|
|
26
|
-
end # module Quickl
|
26
|
+
end # module Quickl
|
data/lib/quickl/version.rb
CHANGED
data/quickl.gemspec
CHANGED
@@ -124,7 +124,6 @@ Gem::Specification.new do |s|
|
|
124
124
|
# for each development dependency. These gems are required for developers
|
125
125
|
#
|
126
126
|
s.add_development_dependency("rake", "~> 0.9.2")
|
127
|
-
s.add_development_dependency("bundler", "~> 1.0")
|
128
127
|
s.add_development_dependency("rspec", "~> 2.6.0")
|
129
128
|
s.add_development_dependency("yard", "~> 0.7.2")
|
130
129
|
s.add_development_dependency("bluecloth", "~> 2.1.0")
|
data/quickl.noespec
CHANGED
@@ -3,18 +3,13 @@
|
|
3
3
|
template-info:
|
4
4
|
name: "ruby"
|
5
5
|
version: 1.4.0
|
6
|
-
manifest:
|
7
|
-
tasks/unit_test.rake:
|
8
|
-
safe-override: false
|
9
|
-
tasks/spec_test.rake:
|
10
|
-
safe-override: false
|
11
6
|
variables:
|
12
7
|
lower:
|
13
8
|
quickl
|
14
9
|
upper:
|
15
10
|
Quickl
|
16
11
|
version:
|
17
|
-
0.
|
12
|
+
0.4.0
|
18
13
|
summary: |-
|
19
14
|
Helper to create commandline ruby programs
|
20
15
|
description: |-
|
@@ -26,9 +21,12 @@ variables:
|
|
26
21
|
links:
|
27
22
|
- http://github.com/blambeau/quickl
|
28
23
|
dependencies:
|
29
|
-
- {name: rake,
|
30
|
-
- {name:
|
31
|
-
- {name:
|
32
|
-
- {name:
|
33
|
-
- {name:
|
34
|
-
|
24
|
+
- {name: rake, version: "~> 0.9.2", groups: [test, release]}
|
25
|
+
- {name: rspec, version: "~> 2.6.0", groups: [test, release]}
|
26
|
+
- {name: yard, version: "~> 0.7.2", groups: [doc ]}
|
27
|
+
- {name: bluecloth, version: "~> 2.1.0", groups: [doc ]}
|
28
|
+
- {name: wlang, version: "~> 0.10.2", groups: [release ]}
|
29
|
+
rake_tasks:
|
30
|
+
unit_test:
|
31
|
+
libs: ["lib", "examples"]
|
32
|
+
pattern: "examples/**/test_*.rb"
|
@@ -11,6 +11,11 @@ module Quickl
|
|
11
11
|
MiniClient::Requester.subcommands.should include(MiniClient::Factored)
|
12
12
|
lambda{ Quickl.sub_command!(MiniClient::Requester, "factored") }.should_not raise_error
|
13
13
|
end
|
14
|
+
|
15
|
+
it "should support installing a specific doc extractor" do
|
16
|
+
MiniClient::Factored.documentation.should eq("Factored doc")
|
17
|
+
MiniClient::Factored.documentation(:upcase => true).should eq("FACTORED DOC")
|
18
|
+
end
|
14
19
|
|
15
20
|
end # Command::command_name
|
16
21
|
end # module Quickl
|
data/spec/mini_client.rb
CHANGED
@@ -100,12 +100,16 @@ class MiniClient < Quickl::Delegator(__FILE__, __LINE__)
|
|
100
100
|
|
101
101
|
end # class Requester
|
102
102
|
|
103
|
-
def self.Factor(
|
104
|
-
Quickl::Command(
|
103
|
+
def self.Factor(arg)
|
104
|
+
Quickl::Command() do |builder|
|
105
105
|
builder.command_parent = MiniClient::Requester
|
106
106
|
builder.callback{|cmd|
|
107
107
|
cmd.instance_eval{ @factored_arg = arg }
|
108
108
|
}
|
109
|
+
builder.doc_extractor = lambda{|cmd,opts|
|
110
|
+
doc = "Factored doc"
|
111
|
+
opts[:upcase] ? doc.upcase : doc
|
112
|
+
}
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
@@ -115,7 +119,7 @@ class MiniClient < Quickl::Delegator(__FILE__, __LINE__)
|
|
115
119
|
# SYNOPSIS
|
116
120
|
# #{MiniClient.command_name} factored
|
117
121
|
#
|
118
|
-
class Factored < Factor(
|
122
|
+
class Factored < Factor(:hello)
|
119
123
|
|
120
124
|
def execute(args)
|
121
125
|
self.class.instance_eval{ @factored_arg }
|
@@ -36,4 +36,13 @@ describe "Quickl.split_commandline_args" do
|
|
36
36
|
it { should eq(expected) }
|
37
37
|
end
|
38
38
|
|
39
|
+
describe "with a specific separator" do
|
40
|
+
subject{ Quickl.split_commandline_args(args, '|') }
|
41
|
+
let(:args){ %w{hello | hello2 hello3 | x } }
|
42
|
+
let(:expected){[
|
43
|
+
%w{hello}, %w{hello2 hello3}, %w{x}
|
44
|
+
]}
|
45
|
+
it { should eq(expected) }
|
46
|
+
end
|
47
|
+
|
39
48
|
end
|
data/tasks/spec_test.rake
CHANGED
data/tasks/unit_test.rake
CHANGED
@@ -31,7 +31,7 @@ begin
|
|
31
31
|
|
32
32
|
# List of directories to added to $LOAD_PATH before running the
|
33
33
|
# tests. (default is 'lib')
|
34
|
-
t.libs = ["lib"]
|
34
|
+
t.libs = ["lib", "examples"]
|
35
35
|
|
36
36
|
# True if verbose test output desired. (default is false)
|
37
37
|
t.verbose = false
|
@@ -57,7 +57,7 @@ begin
|
|
57
57
|
|
58
58
|
# Array of commandline options to pass to ruby when running test
|
59
59
|
# loader.
|
60
|
-
t.ruby_opts = [
|
60
|
+
t.ruby_opts = []
|
61
61
|
|
62
62
|
# Explicitly define the list of test files to be included in a
|
63
63
|
# test. +list+ is expected to be an array of file names (a
|
@@ -68,7 +68,7 @@ begin
|
|
68
68
|
end
|
69
69
|
rescue LoadError => ex
|
70
70
|
task :unit_test do
|
71
|
-
abort
|
71
|
+
abort "rake/testtask does not seem available...\n #{ex.message}"
|
72
72
|
end
|
73
73
|
ensure
|
74
74
|
desc "Run all tests"
|
metadata
CHANGED
@@ -1,132 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickl
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 0.3.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bernard Lambeau
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-08-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &72952360 !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
18
|
+
requirements:
|
25
19
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 63
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 9
|
31
|
-
- 2
|
20
|
+
- !ruby/object:Gem::Version
|
32
21
|
version: 0.9.2
|
33
|
-
version_requirements: *id001
|
34
|
-
name: rake
|
35
|
-
prerelease: false
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
22
|
type: :development
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 15
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 0
|
47
|
-
version: "1.0"
|
48
|
-
version_requirements: *id002
|
49
|
-
name: bundler
|
50
23
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
24
|
+
version_requirements: *72952360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &72951920 !ruby/object:Gem::Requirement
|
54
28
|
none: false
|
55
|
-
requirements:
|
29
|
+
requirements:
|
56
30
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 23
|
59
|
-
segments:
|
60
|
-
- 2
|
61
|
-
- 6
|
62
|
-
- 0
|
31
|
+
- !ruby/object:Gem::Version
|
63
32
|
version: 2.6.0
|
64
|
-
version_requirements: *id003
|
65
|
-
name: rspec
|
66
|
-
prerelease: false
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
33
|
type: :development
|
69
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *72951920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &72951600 !ruby/object:Gem::Requirement
|
70
39
|
none: false
|
71
|
-
requirements:
|
40
|
+
requirements:
|
72
41
|
- - ~>
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 7
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
- 7
|
78
|
-
- 2
|
42
|
+
- !ruby/object:Gem::Version
|
79
43
|
version: 0.7.2
|
80
|
-
version_requirements: *id004
|
81
|
-
name: yard
|
82
|
-
prerelease: false
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
44
|
type: :development
|
85
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *72951600
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bluecloth
|
49
|
+
requirement: &72951210 !ruby/object:Gem::Requirement
|
86
50
|
none: false
|
87
|
-
requirements:
|
51
|
+
requirements:
|
88
52
|
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
hash: 11
|
91
|
-
segments:
|
92
|
-
- 2
|
93
|
-
- 1
|
94
|
-
- 0
|
53
|
+
- !ruby/object:Gem::Version
|
95
54
|
version: 2.1.0
|
96
|
-
version_requirements: *id005
|
97
|
-
name: bluecloth
|
98
|
-
prerelease: false
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
55
|
type: :development
|
101
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *72951210
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: wlang
|
60
|
+
requirement: &72950800 !ruby/object:Gem::Requirement
|
102
61
|
none: false
|
103
|
-
requirements:
|
62
|
+
requirements:
|
104
63
|
- - ~>
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
hash: 51
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
- 10
|
110
|
-
- 2
|
64
|
+
- !ruby/object:Gem::Version
|
111
65
|
version: 0.10.2
|
112
|
-
|
113
|
-
name: wlang
|
66
|
+
type: :development
|
114
67
|
prerelease: false
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
email:
|
68
|
+
version_requirements: *72950800
|
69
|
+
description: ! "Quickl helps you creating commandline ruby programs. From simple commands
|
70
|
+
\nwith options to complex delegators with subcommands, global and local \noptions."
|
71
|
+
email:
|
120
72
|
- blambeau@gmail.com
|
121
|
-
executables:
|
73
|
+
executables:
|
122
74
|
- quickl
|
123
75
|
extensions: []
|
124
|
-
|
125
|
-
extra_rdoc_files:
|
76
|
+
extra_rdoc_files:
|
126
77
|
- README.md
|
127
78
|
- CHANGELOG.md
|
128
79
|
- LICENCE.md
|
129
|
-
files:
|
80
|
+
files:
|
130
81
|
- quickl.gemspec
|
131
82
|
- quickl.noespec
|
132
83
|
- CHANGELOG.md
|
@@ -136,8 +87,9 @@ files:
|
|
136
87
|
- lib/quickl.rb
|
137
88
|
- lib/quickl/command/single.rb
|
138
89
|
- lib/quickl/command/builder.rb
|
90
|
+
- lib/quickl/command/class_methods.rb
|
91
|
+
- lib/quickl/command/instance_methods.rb
|
139
92
|
- lib/quickl/command/options.rb
|
140
|
-
- lib/quickl/command/robustness.rb
|
141
93
|
- lib/quickl/command/delegator.rb
|
142
94
|
- lib/quickl/naming.rb
|
143
95
|
- lib/quickl/errors.rb
|
@@ -192,38 +144,32 @@ files:
|
|
192
144
|
- tasks/debug_mail.txt
|
193
145
|
homepage: http://github.com/blambeau/quickl
|
194
146
|
licenses: []
|
195
|
-
|
196
147
|
post_install_message:
|
197
148
|
rdoc_options: []
|
198
|
-
|
199
|
-
require_paths:
|
149
|
+
require_paths:
|
200
150
|
- lib
|
201
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
152
|
none: false
|
203
|
-
requirements:
|
204
|
-
- -
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
|
207
|
-
segments:
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
segments:
|
208
158
|
- 0
|
209
|
-
|
210
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
hash: -187690143
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
161
|
none: false
|
212
|
-
requirements:
|
213
|
-
- -
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
|
216
|
-
segments:
|
217
|
-
- 0
|
218
|
-
version: "0"
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
219
166
|
requirements: []
|
220
|
-
|
221
167
|
rubyforge_project:
|
222
168
|
rubygems_version: 1.8.6
|
223
169
|
signing_key:
|
224
170
|
specification_version: 3
|
225
171
|
summary: Helper to create commandline ruby programs
|
226
|
-
test_files:
|
172
|
+
test_files:
|
227
173
|
- spec/spec_helper.rb
|
228
174
|
- spec/command/test_command_name.rb
|
229
175
|
- spec/command/test_subcommands.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Quickl
|
2
|
-
class Command
|
3
|
-
module Robustness
|
4
|
-
include Naming
|
5
|
-
|
6
|
-
# Checks that a command whose name is given exists
|
7
|
-
# or raises a NoSuchCommand.
|
8
|
-
def has_command!(name, referer = self.class)
|
9
|
-
Quickl.deprecated("Command#has_command!", "Quickl.sub_command!", caller)
|
10
|
-
Quickl.sub_command!(referer, name)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Checks that _file_ is a readable file or raises an error.
|
14
|
-
# Returns _file_ on success.
|
15
|
-
def valid_read_file!(file, error_class = nil, msg = nil)
|
16
|
-
Quickl.deprecated("Command#valid_read_file!", "Quickl.valid_read_file!", caller)
|
17
|
-
Quickl.valid_read_file!(file, error_class, msg)
|
18
|
-
end
|
19
|
-
|
20
|
-
end # module Robustness
|
21
|
-
end # class Command
|
22
|
-
end # module Quickl
|