quickl 0.1.1 → 0.2.0
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/CHANGELOG.md +10 -0
- data/README.md +5 -5
- data/Rakefile +12 -39
- data/bin/quickl +1 -1
- data/examples/{delegate → delegator}/README.md +12 -12
- data/examples/{delegate/bin/delegate → delegator/bin/delegator} +2 -2
- data/examples/{delegate/lib/delegate.rb → delegator/lib/delegator.rb} +3 -3
- data/examples/{delegate → delegator}/lib/hello_world.rb +2 -2
- data/examples/{delegate → delegator}/lib/help.rb +2 -2
- data/examples/{delegate/test/delegate_test.rb → delegator/test/delegator_test.rb} +4 -4
- data/examples/hello/hello +1 -1
- data/lib/quickl.rb +1 -1
- data/lib/quickl/command.rb +9 -5
- data/lib/quickl/command/{delegate.rb → delegator.rb} +13 -8
- data/lib/quickl/command/robustness.rb +12 -0
- data/lib/quickl/command/single.rb +2 -2
- data/lib/quickl/errors.rb +23 -1
- data/quickl.gemspec +3 -2
- metadata +56 -33
- data/test/command/command_name.spec +0 -16
- data/test/command/documentation.spec +0 -23
- data/test/command/overview.spec +0 -14
- data/test/command/run.spec +0 -22
- data/test/command/subcommands.spec +0 -20
- data/test/command/usage.spec +0 -16
- data/test/mini_client.rb +0 -59
- data/test/naming/command2module.spec +0 -17
- data/test/naming/module2command.spec +0 -21
- data/test/ruby_tools/class_unqualified_name.spec +0 -28
- data/test/ruby_tools/extract_file_rdoc.spec +0 -28
- data/test/ruby_tools/fixtures.rb +0 -27
- data/test/ruby_tools/fixtures/RubyTools.rdoc +0 -12
- data/test/ruby_tools/fixtures/Utils.rdoc +0 -3
- data/test/ruby_tools/optional_args_block_call.spec +0 -37
- data/test/ruby_tools/parent_module.spec +0 -23
- data/test/spec_helper.rb +0 -13
- data/test/wrapping.rb +0 -39
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 0.2.0 / 2011-01-10
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* Command#run now takes a (optional) second argument (get it at command runtime via :requester reader)
|
6
|
+
* Renamed Delegate -> Delegator (Quickl::Delegate is kept but should not be used anymore)
|
7
|
+
* Added IOAccessError with default reaction to Exit
|
8
|
+
* Added valid_read_file! robustness utility
|
9
|
+
* Moved to rspec 2.4.0, modified Rakefile and tests accordingly
|
10
|
+
|
1
11
|
# 0.1.1 / 2010-12-24
|
2
12
|
|
3
13
|
* Fixed gemspec and binaries problems
|
data/README.md
CHANGED
@@ -36,10 +36,10 @@ Running them as simply as:
|
|
36
36
|
|
37
37
|
SimpleCommand.run(ARGV)
|
38
38
|
|
39
|
-
From simple command to complex
|
39
|
+
From simple command to complex delegator (_ala_ 'git [--version] [--help] COMMAND [cmd options] ARGS...'), Quickl provides (or aims at providing) the following features:
|
40
40
|
|
41
41
|
* Simple command creations via simple classes
|
42
|
-
*
|
42
|
+
* Delegator commands and categories via ruby namespaces and naming conventions
|
43
43
|
* Command help and documentation provided through _rdoc_
|
44
44
|
* Command options via standard OptionParser
|
45
45
|
* Error handling trought special blocks, assertions methods and dedicated Error classes
|
@@ -70,7 +70,7 @@ Try this:
|
|
70
70
|
Additional examples (see examples folder):
|
71
71
|
|
72
72
|
* [hello world example](https://github.com/blambeau/quickl/blob/master/examples/hello_world)
|
73
|
-
* [
|
73
|
+
* [delegator example](https://github.com/blambeau/quickl/blob/master/examples/delegator)
|
74
74
|
|
75
75
|
## Version policy
|
76
76
|
|
@@ -81,8 +81,8 @@ Until version 1.0.0, moditications of public interfaces increase the minor versi
|
|
81
81
|
|
82
82
|
Public interfaces are:
|
83
83
|
|
84
|
-
* Quickl::Command and Quickl::
|
85
|
-
* DSL methods used in "subclasses" built by Quickl::Command and Quickl::
|
84
|
+
* Quickl::Command and Quickl::Delegator calls
|
85
|
+
* DSL methods used in "subclasses" built by Quickl::Command and Quickl::Delegator
|
86
86
|
* RDoc -> command line documentation recognizers (synopsis, overview, documentation, ...)
|
87
87
|
* Naming conventions (module <-> command conversions)
|
88
88
|
* Default reactions to errors (Quickl::Help, Quickl::Exit, ...)
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
$here = File.dirname(__FILE__)
|
3
2
|
require 'rubygems'
|
4
3
|
require "rake/testtask"
|
5
|
-
require
|
4
|
+
require "rspec/core/rake_task"
|
6
5
|
require "yard"
|
6
|
+
require "rake/gempackagetask"
|
7
7
|
|
8
8
|
task :default => :test
|
9
9
|
task :test => [:spec, :examples]
|
@@ -11,7 +11,7 @@ task :test => [:spec, :examples]
|
|
11
11
|
# About yard documentation
|
12
12
|
YARD::Rake::YardocTask.new do |t|
|
13
13
|
t.files = ['lib/**/*.rb', 'examples/**/*.rb']
|
14
|
-
t.options = ['--output-dir', 'doc/api', '-', "README.md", "
|
14
|
+
t.options = ['--output-dir', 'doc/api', '-', "README.md", "CHANGELOG.md"]
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Lauches unit tests on examples"
|
@@ -21,44 +21,17 @@ Rake::TestTask.new(:examples) do |test|
|
|
21
21
|
test.verbose = true
|
22
22
|
end
|
23
23
|
|
24
|
-
desc "Run all
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
desc "Run all examples"
|
25
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
26
|
+
t.rspec_opts = %w[--color]
|
27
|
+
t.verbose = false
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
directory 'dist'
|
37
|
-
|
38
|
-
def package(ext='')
|
39
|
-
"dist/#{$spec.name}-#{$spec.version}" + ext
|
40
|
-
end
|
41
|
-
|
42
|
-
file package('.gem') => %w< dist > + $spec.files do |f|
|
43
|
-
sh "gem build quickl.gemspec"
|
44
|
-
mv File.basename(f.name), f.name
|
45
|
-
end
|
46
|
-
|
47
|
-
file package('.tar.gz') => %w< dist > + $spec.files do |f|
|
48
|
-
sh "git archive --format=tar HEAD | gzip > #{f.name}"
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "Build packages"
|
52
|
-
task :package => %w< .gem .tar.gz >.map {|e| package(e) }
|
30
|
+
desc "Create the .gem package"
|
31
|
+
$spec = Kernel.eval(File.read(File.expand_path('../quickl.gemspec', __FILE__)))
|
32
|
+
Rake::GemPackageTask.new($spec) do |pkg|
|
33
|
+
pkg.need_tar = true
|
34
|
+
end
|
53
35
|
|
54
|
-
desc "Build and install as local gem"
|
55
|
-
task :install => package('.gem') do |t|
|
56
|
-
sh "gem install #{package('.gem')}"
|
57
|
-
end
|
58
36
|
|
59
|
-
desc "Upload gem to rubygems.org"
|
60
|
-
task :release => package('.gem') do |t|
|
61
|
-
sh "gem push #{package('.gem')}"
|
62
|
-
end
|
63
|
-
end
|
64
37
|
# vim: syntax=ruby
|
data/bin/quickl
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
# Quickl example:
|
1
|
+
# Quickl example: delegator
|
2
2
|
|
3
|
-
This example shows how to
|
3
|
+
This example shows how to create delegator commands. Delegators are commands
|
4
4
|
that delegate the actual execution to sub commands (well known example is
|
5
|
-
'git'). A
|
5
|
+
'git'). A delegator command typically has a signature like:
|
6
6
|
|
7
|
-
|
7
|
+
delegator [main options] COMMAND [cmd options] ARGS...
|
8
8
|
|
9
9
|
## Structure
|
10
10
|
|
11
|
-
The structure for
|
11
|
+
The structure for delegator commands is as follows:
|
12
12
|
|
13
13
|
#
|
14
14
|
# Main command overview
|
@@ -27,7 +27,7 @@ The structure for delegate commands is as follows:
|
|
27
27
|
#
|
28
28
|
# See '#{command_name} help COMMAND' for more information on a specific command.
|
29
29
|
#
|
30
|
-
class
|
30
|
+
class DelegatorCommand < Quickl::Delegator(__FILE__, __LINE__)
|
31
31
|
|
32
32
|
# install options below
|
33
33
|
options do |opt|
|
@@ -60,26 +60,26 @@ The structure for delegate commands is as follows:
|
|
60
60
|
|
61
61
|
# To run the command, typically in a bin/simple_command
|
62
62
|
# shell file
|
63
|
-
|
63
|
+
DelegatorCommand.run(ARGV)
|
64
64
|
|
65
65
|
|
66
66
|
## Example
|
67
67
|
|
68
68
|
Try the following:
|
69
69
|
|
70
|
-
./
|
70
|
+
./delegator
|
71
71
|
# => [ ... complete help with subcommands summary ... ]
|
72
72
|
|
73
|
-
./
|
73
|
+
./delegator --help
|
74
74
|
# => [ ... complete help with subcommands summary ... ]
|
75
75
|
|
76
|
-
./
|
76
|
+
./delegator help
|
77
77
|
# => [ ... complete help with subcommands summary ... ]
|
78
78
|
|
79
|
-
./
|
79
|
+
./delegator help hello-world
|
80
80
|
# => [ ... help of hello-world's subcommand ... ]
|
81
81
|
|
82
|
-
./
|
82
|
+
./delegator hello-world bob
|
83
83
|
# => Hello bob!
|
84
84
|
|
85
85
|
./hello_world --capitalize bob
|
@@ -11,12 +11,12 @@
|
|
11
11
|
# #{summarized_subcommands}
|
12
12
|
#
|
13
13
|
# DESCRIPTION
|
14
|
-
# This example shows how to write a
|
14
|
+
# This example shows how to write a delegator command, that is, a
|
15
15
|
# command which delegates to a subcommand
|
16
16
|
#
|
17
17
|
# See '#{program_name} help COMMAND' for more information on a specific command.
|
18
18
|
#
|
19
|
-
class
|
19
|
+
class Delegator < Quickl::Delegator(__FILE__, __LINE__)
|
20
20
|
|
21
21
|
# Single command version
|
22
22
|
VERSION = "0.1.0"
|
@@ -36,6 +36,6 @@ class Delegate < Quickl::Delegate(__FILE__, __LINE__)
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
end # class
|
39
|
+
end # class Delegator
|
40
40
|
require "help"
|
41
41
|
require "hello_world"
|
@@ -7,9 +7,9 @@ rescue LoadError
|
|
7
7
|
require 'quickl'
|
8
8
|
end
|
9
9
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
10
|
-
require '
|
10
|
+
require 'Delegator'
|
11
11
|
|
12
|
-
class
|
12
|
+
class DelegatorTest < Test::Unit::TestCase
|
13
13
|
|
14
14
|
def assert_exits(match, exit_code)
|
15
15
|
yield
|
@@ -21,8 +21,8 @@ class DelegateTest < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def run_command(*args)
|
23
23
|
$stdout = StringIO.new
|
24
|
-
|
25
|
-
|
24
|
+
Delegator.no_react_to(Quickl::Exit)
|
25
|
+
Delegator.run args
|
26
26
|
$stdout.string
|
27
27
|
ensure
|
28
28
|
$stdout = STDOUT
|
data/examples/hello/hello
CHANGED
data/lib/quickl.rb
CHANGED
data/lib/quickl/command.rb
CHANGED
@@ -72,8 +72,8 @@ module Quickl
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Runs the command
|
75
|
-
def run(
|
76
|
-
self.new.run(
|
75
|
+
def run(argv = [], requester = nil)
|
76
|
+
self.new.run(argv, requester)
|
77
77
|
end
|
78
78
|
|
79
79
|
############################################### Error handling
|
@@ -100,7 +100,10 @@ module Quickl
|
|
100
100
|
|
101
101
|
# Methods installed on all command instances
|
102
102
|
module InstanceMethods
|
103
|
-
|
103
|
+
|
104
|
+
# Who is requesting command execution?
|
105
|
+
attr_reader :requester
|
106
|
+
|
104
107
|
# Delegate unrecognized calls to the command class
|
105
108
|
# (gives access to options, help, usage, ...)
|
106
109
|
def method_missing(name, *args, &block)
|
@@ -132,7 +135,8 @@ module Quickl
|
|
132
135
|
# This method is intended to be overriden and does nothing
|
133
136
|
# by default.
|
134
137
|
#
|
135
|
-
def run(argv)
|
138
|
+
def run(argv, requester = nil)
|
139
|
+
@requester = requester
|
136
140
|
_run(argv)
|
137
141
|
rescue Quickl::Error => ex
|
138
142
|
handle_error(ex)
|
@@ -151,4 +155,4 @@ require 'quickl/command/builder'
|
|
151
155
|
require 'quickl/command/robustness'
|
152
156
|
require 'quickl/command/options'
|
153
157
|
require 'quickl/command/single'
|
154
|
-
require 'quickl/command/
|
158
|
+
require 'quickl/command/delegator'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Quickl
|
2
|
-
module Command::
|
2
|
+
module Command::Delegator
|
3
3
|
module InstanceMethods
|
4
|
-
|
4
|
+
|
5
5
|
# Run the command by delegation
|
6
6
|
def _run(argv = [])
|
7
7
|
# My own options
|
@@ -13,7 +13,7 @@ module Quickl
|
|
13
13
|
|
14
14
|
# Run the subcommand now
|
15
15
|
if cmd = argv.shift
|
16
|
-
has_command!(cmd).run(argv)
|
16
|
+
cmd = has_command!(cmd).run(argv, self)
|
17
17
|
else
|
18
18
|
raise Quickl::Help.new(cmd.nil? ? 0 : -1)
|
19
19
|
end
|
@@ -36,18 +36,23 @@ module Quickl
|
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
|
-
end # module Command::
|
39
|
+
end # module Command::Delegator
|
40
40
|
|
41
41
|
#
|
42
|
-
# Create a
|
42
|
+
# Create a delegator command
|
43
43
|
#
|
44
|
-
def self.
|
44
|
+
def self.Delegator(*args)
|
45
45
|
command_builder do |b|
|
46
46
|
b.document *args
|
47
|
-
b.class_module Command::
|
48
|
-
b.instance_module Command::
|
47
|
+
b.class_module Command::Delegator::ClassMethods
|
48
|
+
b.instance_module Command::Delegator::InstanceMethods
|
49
49
|
end
|
50
50
|
Command
|
51
51
|
end
|
52
52
|
|
53
|
+
# @see Delegator
|
54
|
+
def self.Delegate(*args)
|
55
|
+
self.Delegator(*args)
|
56
|
+
end
|
57
|
+
|
53
58
|
end # module Quickl
|
@@ -13,6 +13,18 @@ module Quickl
|
|
13
13
|
raise NoSuchCommand, "No such command #{name}", ex.backtrace
|
14
14
|
end
|
15
15
|
|
16
|
+
# Checks that _file_ is a readable file or raises an error.
|
17
|
+
# Returns _file_ on success.
|
18
|
+
def valid_read_file!(file, error_class = nil, msg = nil)
|
19
|
+
if File.file?(file) and File.readable?(file)
|
20
|
+
file
|
21
|
+
else
|
22
|
+
error_class ||= Quickl::IOAccessError
|
23
|
+
msg ||= "Not a file or not readable: #{file}"
|
24
|
+
raise error_class, msg, caller
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
16
28
|
end # module Robustness
|
17
29
|
end # class Command
|
18
30
|
end # module Quickl
|
data/lib/quickl/errors.rb
CHANGED
@@ -173,7 +173,7 @@ module Quickl
|
|
173
173
|
|
174
174
|
#
|
175
175
|
# This error can be raised to indicate that a command has not been
|
176
|
-
# found (typically by
|
176
|
+
# found (typically by delegators).
|
177
177
|
#
|
178
178
|
# Default exit code:
|
179
179
|
# -1
|
@@ -193,4 +193,26 @@ module Quickl
|
|
193
193
|
|
194
194
|
end # class NoSuchCommand
|
195
195
|
|
196
|
+
#
|
197
|
+
# This error can be raised to indicate that some file/dir
|
198
|
+
# access has failed.
|
199
|
+
#
|
200
|
+
# Default exit code:
|
201
|
+
# -1
|
202
|
+
#
|
203
|
+
# Default reaction:
|
204
|
+
# raise Exit.new(code), message, backtrace
|
205
|
+
#
|
206
|
+
class IOAccessError < Error
|
207
|
+
|
208
|
+
def initialize(*args)
|
209
|
+
super(*(args + [ -1 ]))
|
210
|
+
end
|
211
|
+
|
212
|
+
def react!
|
213
|
+
raise Exit.new(self.exit_code), self.message, backtrace
|
214
|
+
end
|
215
|
+
|
216
|
+
end # class IOAccessError
|
217
|
+
|
196
218
|
end # module Quickl
|
data/quickl.gemspec
CHANGED
@@ -23,12 +23,13 @@ Gem::Specification.new do |s|
|
|
23
23
|
Dir['test/**/*'] +
|
24
24
|
%w{ quickl.gemspec Rakefile README.md CHANGELOG.md }
|
25
25
|
|
26
|
-
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/ }
|
27
|
-
|
28
26
|
s.bindir = "bin"
|
29
27
|
s.executables = ["quickl"]
|
30
28
|
|
31
29
|
s.add_development_dependency('rake')
|
30
|
+
s.add_development_dependency('rspec', ">= 2.4.0")
|
31
|
+
s.add_development_dependency('yard', ">= 0.6.4")
|
32
|
+
s.add_development_dependency('bluecloth', ">= 0.6.4")
|
32
33
|
|
33
34
|
s.has_rdoc = true
|
34
35
|
s.rdoc_options = %w< --line-numbers --inline-source --title Quickl --main Quickl >
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Bernard Lambeau
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-10 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +25,56 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
33
31
|
type: :development
|
34
32
|
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 4
|
44
|
+
- 0
|
45
|
+
version: 2.4.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
- 6
|
59
|
+
- 4
|
60
|
+
version: 0.6.4
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bluecloth
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
- 6
|
74
|
+
- 4
|
75
|
+
version: 0.6.4
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
35
78
|
description: Generate Ruby command line apps quickly
|
36
79
|
email: blambeau@gmail.com
|
37
80
|
executables:
|
@@ -42,7 +85,7 @@ extra_rdoc_files:
|
|
42
85
|
- README.md
|
43
86
|
files:
|
44
87
|
- lib/quickl/command/builder.rb
|
45
|
-
- lib/quickl/command/
|
88
|
+
- lib/quickl/command/delegator.rb
|
46
89
|
- lib/quickl/command/options.rb
|
47
90
|
- lib/quickl/command/robustness.rb
|
48
91
|
- lib/quickl/command/single.rb
|
@@ -52,36 +95,18 @@ files:
|
|
52
95
|
- lib/quickl/naming.rb
|
53
96
|
- lib/quickl/ruby_tools.rb
|
54
97
|
- lib/quickl.rb
|
55
|
-
- examples/
|
56
|
-
- examples/
|
57
|
-
- examples/
|
58
|
-
- examples/
|
59
|
-
- examples/
|
60
|
-
- examples/
|
98
|
+
- examples/delegator/bin/delegator
|
99
|
+
- examples/delegator/lib/delegator.rb
|
100
|
+
- examples/delegator/lib/hello_world.rb
|
101
|
+
- examples/delegator/lib/help.rb
|
102
|
+
- examples/delegator/README.md
|
103
|
+
- examples/delegator/test/delegator_test.rb
|
61
104
|
- examples/hello/hello
|
62
105
|
- examples/hello/hello_test.rb
|
63
106
|
- examples/hello/README.md
|
64
107
|
- examples/helper.rb
|
65
108
|
- templates/single.erb
|
66
109
|
- bin/quickl
|
67
|
-
- test/command/command_name.spec
|
68
|
-
- test/command/documentation.spec
|
69
|
-
- test/command/overview.spec
|
70
|
-
- test/command/run.spec
|
71
|
-
- test/command/subcommands.spec
|
72
|
-
- test/command/usage.spec
|
73
|
-
- test/mini_client.rb
|
74
|
-
- test/naming/command2module.spec
|
75
|
-
- test/naming/module2command.spec
|
76
|
-
- test/ruby_tools/class_unqualified_name.spec
|
77
|
-
- test/ruby_tools/extract_file_rdoc.spec
|
78
|
-
- test/ruby_tools/fixtures/RubyTools.rdoc
|
79
|
-
- test/ruby_tools/fixtures/Utils.rdoc
|
80
|
-
- test/ruby_tools/fixtures.rb
|
81
|
-
- test/ruby_tools/optional_args_block_call.spec
|
82
|
-
- test/ruby_tools/parent_module.spec
|
83
|
-
- test/spec_helper.rb
|
84
|
-
- test/wrapping.rb
|
85
110
|
- quickl.gemspec
|
86
111
|
- Rakefile
|
87
112
|
- README.md
|
@@ -105,7 +130,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
130
|
requirements:
|
106
131
|
- - ">="
|
107
132
|
- !ruby/object:Gem::Version
|
108
|
-
hash: 3
|
109
133
|
segments:
|
110
134
|
- 0
|
111
135
|
version: "0"
|
@@ -114,7 +138,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
138
|
requirements:
|
115
139
|
- - ">="
|
116
140
|
- !ruby/object:Gem::Version
|
117
|
-
hash: 3
|
118
141
|
segments:
|
119
142
|
- 0
|
120
143
|
version: "0"
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Command::command_name /" do
|
4
|
-
|
5
|
-
it "should be installed from inline rdoc" do
|
6
|
-
MiniClient::Say::Hello.command_name.should == "hello"
|
7
|
-
MiniClient::Say::Goodbye.command_name.should == "goodbye"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should be accessible on instance" do
|
11
|
-
MiniClient::Say::Hello.new.command_name.should == "hello"
|
12
|
-
MiniClient::Say::Goodbye.new.command_name.should == "goodbye"
|
13
|
-
end
|
14
|
-
|
15
|
-
end # Command::command_name
|
16
|
-
end # module Quickl
|
@@ -1,23 +0,0 @@
|
|
1
|
-
$hello_doc = <<EOF
|
2
|
-
|
3
|
-
Say hello to the user whose name is requested on the standard input
|
4
|
-
|
5
|
-
SYNOPSIS
|
6
|
-
mini-client say:hello
|
7
|
-
|
8
|
-
DESCRIPTION
|
9
|
-
And an explanation here
|
10
|
-
on multiple lines with replacement: hello
|
11
|
-
|
12
|
-
EOF
|
13
|
-
|
14
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
15
|
-
module Quickl
|
16
|
-
describe "Command::documentation /" do
|
17
|
-
|
18
|
-
it "should be correctly installed" do
|
19
|
-
MiniClient::Say::Hello.documentation.should == $hello_doc[0..-1]
|
20
|
-
end
|
21
|
-
|
22
|
-
end # Command::command
|
23
|
-
end # module Quickl
|
data/test/command/overview.spec
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Command::overview /" do
|
4
|
-
|
5
|
-
it "should be installed from inline rdoc" do
|
6
|
-
MiniClient::Help.overview.should == "Print help"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should be installed accessible on instance" do
|
10
|
-
MiniClient::Help.new.overview.should == "Print help"
|
11
|
-
end
|
12
|
-
|
13
|
-
end # Command::overview
|
14
|
-
end # module Quickl
|
data/test/command/run.spec
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Command::run /" do
|
4
|
-
|
5
|
-
it "when invoked on a terminal command" do
|
6
|
-
MiniClient::Say::Hello.run.should == :hello
|
7
|
-
MiniClient::Say::Goodbye.run.should == :goodbye
|
8
|
-
end
|
9
|
-
|
10
|
-
it "when invoked on a delegate command" do
|
11
|
-
MiniClient.run(["help"]).should == :help
|
12
|
-
MiniClient::Say.run(["hello"]).should == :hello
|
13
|
-
MiniClient::Say.run(["goodbye"]).should == :goodbye
|
14
|
-
end
|
15
|
-
|
16
|
-
it "when invoked on qualified command names" do
|
17
|
-
MiniClient.run(["say:hello"]).should == :hello
|
18
|
-
MiniClient.run(["say:goodbye"]).should == :goodbye
|
19
|
-
end
|
20
|
-
|
21
|
-
end # Command::command
|
22
|
-
end # module Quickl
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Command::subcommands /" do
|
4
|
-
|
5
|
-
it "should return installed commands in an array" do
|
6
|
-
MiniClient.subcommands.should == [
|
7
|
-
MiniClient::Help,
|
8
|
-
MiniClient::Say
|
9
|
-
]
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return installed commands in an array" do
|
13
|
-
MiniClient::Say.subcommands.should == [
|
14
|
-
MiniClient::Say::Hello,
|
15
|
-
MiniClient::Say::Goodbye
|
16
|
-
]
|
17
|
-
end
|
18
|
-
|
19
|
-
end # Command::subcommand
|
20
|
-
end # module Quickl
|
data/test/command/usage.spec
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Command::usage /" do
|
4
|
-
|
5
|
-
it "should be installed from inline rdoc" do
|
6
|
-
MiniClient::Say::Hello.usage.should == "mini-client say:hello"
|
7
|
-
MiniClient::Say::Goodbye.usage.should == "mini-client say:goodbye"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should be accessible on instance" do
|
11
|
-
MiniClient::Say::Hello.new.usage.should == "mini-client say:hello"
|
12
|
-
MiniClient::Say::Goodbye.new.usage.should == "mini-client say:goodbye"
|
13
|
-
end
|
14
|
-
|
15
|
-
end # Command::usage
|
16
|
-
end # module Quickl
|
data/test/mini_client.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# MiniClient main command
|
3
|
-
#
|
4
|
-
class MiniClient < Quickl::Delegate(__FILE__, __LINE__)
|
5
|
-
|
6
|
-
#
|
7
|
-
# Print help
|
8
|
-
#
|
9
|
-
# SYNOPSIS
|
10
|
-
# #{MiniClient.command_name} help
|
11
|
-
#
|
12
|
-
# DESCRIPTION
|
13
|
-
# #{command_name} prints help
|
14
|
-
#
|
15
|
-
class Help < Quickl::Command(__FILE__, __LINE__)
|
16
|
-
|
17
|
-
def run(*args)
|
18
|
-
:help
|
19
|
-
end
|
20
|
-
|
21
|
-
end # class Help
|
22
|
-
|
23
|
-
class Say < Quickl::Delegate(__FILE__, __LINE__)
|
24
|
-
|
25
|
-
#
|
26
|
-
# Say hello to the user whose name is requested on the standard input
|
27
|
-
#
|
28
|
-
# SYNOPSIS
|
29
|
-
# #{MiniClient.command_name} say:hello
|
30
|
-
#
|
31
|
-
# DESCRIPTION
|
32
|
-
# And an explanation here
|
33
|
-
# on multiple lines with replacement: #{command_name}
|
34
|
-
#
|
35
|
-
class Hello < Quickl::Command(__FILE__, __LINE__)
|
36
|
-
|
37
|
-
def run(*args)
|
38
|
-
:hello
|
39
|
-
end
|
40
|
-
|
41
|
-
end # class Hello
|
42
|
-
|
43
|
-
#
|
44
|
-
# Say goodbye to the currently connected user
|
45
|
-
#
|
46
|
-
# SYNOPSIS
|
47
|
-
# #{MiniClient.command_name} say:goodbye
|
48
|
-
#
|
49
|
-
class Goodbye < Quickl::Command(__FILE__, __LINE__)
|
50
|
-
|
51
|
-
def run(*args)
|
52
|
-
:goodbye
|
53
|
-
end
|
54
|
-
|
55
|
-
end # class Goodbye
|
56
|
-
|
57
|
-
end # class Say
|
58
|
-
|
59
|
-
end # module MiniClient
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Naming::command2module /" do
|
4
|
-
include Naming
|
5
|
-
|
6
|
-
it "should capitalize first char" do
|
7
|
-
command2module("say").should == "Say"
|
8
|
-
command2module(:say).should == :Say
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should capitalize support dashes" do
|
12
|
-
command2module("say-hello").should == "SayHello"
|
13
|
-
command2module(:"say-hello").should == :SayHello
|
14
|
-
end
|
15
|
-
|
16
|
-
end # module Quickl
|
17
|
-
end # module Quickl
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "Naming::module2command /" do
|
4
|
-
include Naming
|
5
|
-
|
6
|
-
it "should uncapitalize first char" do
|
7
|
-
module2command("Say").should == "say"
|
8
|
-
module2command(:Say).should == :say
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should uncapitalize and introduce dashes" do
|
12
|
-
module2command("SayHello").should == "say-hello"
|
13
|
-
module2command(:"SayHello").should == :"say-hello"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should support taking modules as argument" do
|
17
|
-
module2command(Quickl::Command).should == "command"
|
18
|
-
end
|
19
|
-
|
20
|
-
end # module Quickl
|
21
|
-
end # module Quickl
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../fixtures', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "RubyTools#class_unqualified_name /" do
|
4
|
-
|
5
|
-
subject{ RubyTools::class_unqualified_name(clazz) }
|
6
|
-
|
7
|
-
describe "when called on unqualified class" do
|
8
|
-
let(:clazz){ ::String }
|
9
|
-
it{ should == "String" }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "when called on qualified class" do
|
13
|
-
let(:clazz){ RubyTools }
|
14
|
-
it{ should == "RubyTools" }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when called on long qualified class" do
|
18
|
-
let(:clazz){ Quickl::Fixtures::Utils }
|
19
|
-
it{ should == "Utils" }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "when piped with parent_module" do
|
23
|
-
let(:clazz){ RubyTools::parent_module(Quickl::Fixtures::Utils) }
|
24
|
-
it{ should == "Fixtures" }
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path('../fixtures', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "RubyTools#extract_file_rdoc /" do
|
4
|
-
|
5
|
-
let(:file){ File.expand_path('../fixtures.rb', __FILE__) }
|
6
|
-
|
7
|
-
describe "when used without line and reverse options" do
|
8
|
-
|
9
|
-
subject{ RubyTools::extract_file_rdoc(file) }
|
10
|
-
|
11
|
-
it "should be as expected" do
|
12
|
-
subject.should == File.read(File.expand_path('../fixtures/RubyTools.rdoc', __FILE__))
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when used with line and reverse options" do
|
18
|
-
|
19
|
-
subject{ RubyTools::extract_file_rdoc(file, 23, true) }
|
20
|
-
|
21
|
-
it "should be as expected" do
|
22
|
-
subject.should == File.read(File.expand_path('../fixtures/Utils.rdoc', __FILE__))
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end # RubyTools#extract_file_rdoc
|
28
|
-
end # module Quickl
|
data/test/ruby_tools/fixtures.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
module Fixtures
|
4
|
-
|
5
|
-
#
|
6
|
-
# This is a fixtures helper that matches documentation conventions.
|
7
|
-
#
|
8
|
-
# This is a second paragraph
|
9
|
-
# That append on two lines
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# WARNING:
|
13
|
-
# This kind of indentation should not be interpreted as code
|
14
|
-
#
|
15
|
-
# But this one yes
|
16
|
-
#
|
17
|
-
module RubyTools
|
18
|
-
end # module RubyTools
|
19
|
-
|
20
|
-
#
|
21
|
-
# This is the documentation of the Utils module
|
22
|
-
#
|
23
|
-
module Utils
|
24
|
-
end # module Utils
|
25
|
-
|
26
|
-
end # module Fixtures
|
27
|
-
end # module Quickl
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path('../fixtures', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "RubyTools#optional_args_block_call /" do
|
4
|
-
|
5
|
-
subject{ RubyTools::optional_args_block_call(block, args) }
|
6
|
-
|
7
|
-
describe "when block has no arguments /" do
|
8
|
-
let(:block){ lambda {
|
9
|
-
"ok"
|
10
|
-
} }
|
11
|
-
|
12
|
-
describe "when no args are given" do
|
13
|
-
let(:args){ [ ] }
|
14
|
-
it { should == "ok" }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when no args are given" do
|
18
|
-
let(:args){ [ "hello" ] }
|
19
|
-
it { should == "ok" }
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "when block has one arguments /" do
|
25
|
-
let(:block){ lambda {|name|
|
26
|
-
name
|
27
|
-
} }
|
28
|
-
|
29
|
-
describe "when args are given" do
|
30
|
-
let(:args){ [ "hello" ] }
|
31
|
-
it { should == "hello" }
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path('../fixtures', __FILE__)
|
2
|
-
module Quickl
|
3
|
-
describe "RubyTools#parent_module /" do
|
4
|
-
|
5
|
-
subject{ RubyTools::parent_module(clazz) }
|
6
|
-
|
7
|
-
describe "when called on unqualified class" do
|
8
|
-
let(:clazz){ ::String }
|
9
|
-
it{ should be_nil }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "when called on qualified class" do
|
13
|
-
let(:clazz){ RubyTools }
|
14
|
-
it{ should == Quickl }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when called on long qualified class" do
|
18
|
-
let(:clazz){ Quickl::Fixtures::Utils }
|
19
|
-
it{ should == Quickl::Fixtures }
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/test/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
dir = File.dirname(__FILE__)
|
2
|
-
$LOAD_PATH.unshift "#{dir}/../lib"
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'spec'
|
6
|
-
require 'spec/autorun'
|
7
|
-
require 'pp'
|
8
|
-
require 'fileutils'
|
9
|
-
require 'quickl'
|
10
|
-
require 'mini_client'
|
11
|
-
|
12
|
-
Spec::Runner.configure do |config|
|
13
|
-
end
|
data/test/wrapping.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift('../../lib', __FILE__)
|
2
|
-
require "quickl"
|
3
|
-
$wrappers = []
|
4
|
-
|
5
|
-
def wrap(filter, &block)
|
6
|
-
$wrappers << [ filter, block ]
|
7
|
-
end
|
8
|
-
|
9
|
-
def build_wrapper(command, filter, continuation)
|
10
|
-
lambda{|cont|
|
11
|
-
if !filter || command.instance_eval(&filter)
|
12
|
-
command.instance_exec(continuation, &b)
|
13
|
-
else
|
14
|
-
continuation.call
|
15
|
-
end
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def execute(command, &block)
|
20
|
-
first = build_wrapper(command, *$wrappers.first)
|
21
|
-
c = $wrappers[1..-1].inject(first){|cont,wrapper|
|
22
|
-
build_wrapper(command, *wrapper)
|
23
|
-
}
|
24
|
-
c.call(block)
|
25
|
-
end
|
26
|
-
|
27
|
-
wrap(lambda{ true }){|cont|
|
28
|
-
puts "wrap 1"
|
29
|
-
cont.call
|
30
|
-
puts "end wrap 1"
|
31
|
-
}
|
32
|
-
wrap(lambda{ true }){|cont|
|
33
|
-
puts "wrap 2"
|
34
|
-
cont.call
|
35
|
-
puts "end wrap 2"
|
36
|
-
}
|
37
|
-
execute(self){
|
38
|
-
puts "hello"
|
39
|
-
}
|