quickl 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +23 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +34 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +15 -0
- data/README.md +0 -25
- data/Rakefile +18 -32
- data/lib/quickl/command/builder.rb +18 -1
- data/lib/quickl/command/delegator.rb +8 -5
- data/lib/quickl/command/robustness.rb +4 -5
- data/lib/quickl/command/single.rb +1 -0
- data/lib/quickl/command.rb +12 -0
- data/lib/quickl/loader.rb +0 -0
- data/lib/quickl/version.rb +14 -0
- data/lib/quickl.rb +3 -4
- data/quickl.gemspec +178 -27
- data/quickl.noespec +58 -0
- data/spec/command/command_building_spec.rb +16 -0
- data/spec/command/command_name_spec.rb +16 -0
- data/spec/command/documentation_spec.rb +23 -0
- data/spec/command/overview_spec.rb +14 -0
- data/spec/command/requester_spec.rb +16 -0
- data/spec/command/robustness/valid_read_file_spec.rb +62 -0
- data/spec/command/run_spec.rb +22 -0
- data/spec/command/subcommand_by_name_spec.rb +15 -0
- data/spec/command/subcommands_spec.rb +24 -0
- data/spec/command/usage_spec.rb +16 -0
- data/spec/mini_client.rb +96 -0
- data/spec/naming/command2module_spec.rb +17 -0
- data/spec/naming/module2command_spec.rb +21 -0
- data/spec/quickl_spec.rb +8 -0
- data/spec/ruby_tools/class_unqualified_name_spec.rb +28 -0
- data/spec/ruby_tools/extract_file_rdoc_spec.rb +28 -0
- data/spec/ruby_tools/fixtures/RubyTools.rdoc +12 -0
- data/spec/ruby_tools/fixtures/Utils.rdoc +3 -0
- data/spec/ruby_tools/fixtures.rb +27 -0
- data/spec/ruby_tools/optional_args_block_call_spec.rb +37 -0
- data/spec/ruby_tools/parent_module_spec.rb +23 -0
- data/spec/spec_helper.rb +4 -0
- data/tasks/debug_mail.rake +78 -0
- data/tasks/debug_mail.txt +13 -0
- data/tasks/gem.rake +68 -0
- data/tasks/spec_test.rake +79 -0
- data/tasks/unit_test.rake +77 -0
- data/tasks/yard.rake +51 -0
- metadata +150 -105
- data/examples/delegator/README.md +0 -86
- data/examples/delegator/bin/delegator +0 -9
- data/examples/delegator/lib/delegator.rb +0 -41
- data/examples/delegator/lib/hello_world.rb +0 -39
- data/examples/delegator/lib/help.rb +0 -24
- data/examples/delegator/test/delegator_test.rb +0 -68
- data/examples/hello/README.md +0 -74
- data/examples/hello/hello +0 -57
- data/examples/hello/hello_test.rb +0 -65
- data/examples/helper.rb +0 -6
- data/templates/single.erb +0 -40
@@ -1,24 +0,0 @@
|
|
1
|
-
class Delegator
|
2
|
-
#
|
3
|
-
# Show help about a specific command
|
4
|
-
#
|
5
|
-
# SYNOPSIS
|
6
|
-
# #{program_name} #{command_name} help COMMAND
|
7
|
-
#
|
8
|
-
class Help < Quickl::Command(__FILE__, __LINE__)
|
9
|
-
|
10
|
-
# Let NoSuchCommandError be passed to higher stage
|
11
|
-
no_react_to Quickl::NoSuchCommand
|
12
|
-
|
13
|
-
# Command execution
|
14
|
-
def execute(args)
|
15
|
-
if args.size != 1
|
16
|
-
puts super_command.help
|
17
|
-
else
|
18
|
-
cmd = has_command!(args.first, super_command)
|
19
|
-
puts cmd.help
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end # class Help
|
24
|
-
end # class Delegator
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stringio'
|
3
|
-
begin
|
4
|
-
require 'quickl'
|
5
|
-
rescue LoadError
|
6
|
-
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
7
|
-
require 'quickl'
|
8
|
-
end
|
9
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
10
|
-
require 'Delegator'
|
11
|
-
|
12
|
-
class DelegatorTest < Test::Unit::TestCase
|
13
|
-
|
14
|
-
def assert_exits(match, exit_code)
|
15
|
-
yield
|
16
|
-
assert_false true, "Expected to exit with #{match}, nothing raised"
|
17
|
-
rescue Quickl::Exit => ex
|
18
|
-
assert_equal ex.exit_code, exit_code
|
19
|
-
assert ex.message =~ match
|
20
|
-
end
|
21
|
-
|
22
|
-
def run_command(*args)
|
23
|
-
$stdout = StringIO.new
|
24
|
-
Delegator.no_react_to(Quickl::Exit)
|
25
|
-
Delegator.run args
|
26
|
-
$stdout.string
|
27
|
-
ensure
|
28
|
-
$stdout = STDOUT
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_alone
|
32
|
-
assert_exits(/Delegate execution to a sub command/, 0){ run_command }
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_help_option
|
36
|
-
assert_exits(/DESCRIPTION/, 0){
|
37
|
-
run_command("--help")
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_version_option
|
42
|
-
assert_exits(/(c)/, 0){
|
43
|
-
run_command("--version")
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_no_such_option
|
48
|
-
assert_exits(/invalid option/, -1){
|
49
|
-
run_command("--no-such-option")
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_help_delegation
|
54
|
-
assert run_command("help", "hello-world") =~ /Say hello/
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_hello_delegation
|
58
|
-
assert_equal "Hello world!\n", run_command("hello-world")
|
59
|
-
assert_equal "Hello bob!\n", run_command("hello-world", "bob")
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_hello_capitalize
|
63
|
-
assert_equal "Hello World!\n", run_command("hello-world", "--capitalize")
|
64
|
-
assert_equal "Hello Bob!\n", run_command("hello-world", "bob", "--capitalize")
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
data/examples/hello/README.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Quickl example: hello
|
2
|
-
|
3
|
-
This example shows how to create a really simple commandline program.
|
4
|
-
|
5
|
-
## Structure
|
6
|
-
|
7
|
-
The structure it follows is simply:
|
8
|
-
|
9
|
-
#
|
10
|
-
# Short description here
|
11
|
-
#
|
12
|
-
# SYNOPSIS
|
13
|
-
# Usage: ...
|
14
|
-
#
|
15
|
-
# OPTIONS
|
16
|
-
# #{sumarized_options}
|
17
|
-
#
|
18
|
-
# DESCRIPTION
|
19
|
-
# Long description here...
|
20
|
-
#
|
21
|
-
class SimpleCommand < Quickl::Command(__FILE__, __LINE__)
|
22
|
-
|
23
|
-
# install options below
|
24
|
-
options do |opt|
|
25
|
-
# _opt_ is an OptionParser instance
|
26
|
-
end
|
27
|
-
|
28
|
-
# install the code to run the command
|
29
|
-
def execute(args)
|
30
|
-
# _args_ are non-option command line parameters
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
# To run the command, typically in a bin/simple_command
|
36
|
-
# shell file
|
37
|
-
SimpleCommand.run(ARGV)
|
38
|
-
|
39
|
-
|
40
|
-
## Example
|
41
|
-
|
42
|
-
Try the following:
|
43
|
-
|
44
|
-
./hello
|
45
|
-
# => Hello world!
|
46
|
-
|
47
|
-
./hello --capitalize
|
48
|
-
# => Hello World!
|
49
|
-
|
50
|
-
./hello bob
|
51
|
-
# => Hello bob!
|
52
|
-
|
53
|
-
./hello --capitalize bob
|
54
|
-
# => Hello Bob!
|
55
|
-
|
56
|
-
./hello --version
|
57
|
-
# => hello 0.1.0 (c) 2010, Bernard Lambeau
|
58
|
-
|
59
|
-
./hello --help
|
60
|
-
# => ...
|
61
|
-
|
62
|
-
./hello too many arguments
|
63
|
-
# => needless argument: too many arguments
|
64
|
-
# => hello [--help] [--version] [--capitalize] [WHO]
|
65
|
-
|
66
|
-
./hello --no-such-option
|
67
|
-
# invalid option: --no-such-option
|
68
|
-
# hello [--help] [--version] [--capitalize] [WHO]
|
69
|
-
|
70
|
-
## You have to known that ...
|
71
|
-
|
72
|
-
* An **instance** of command is actually executed. Therefore, it is safe to install instance variables through options and to use them in execute().
|
73
|
-
* Documentation shown with --help is the rdoc documentation evaluated in the binding of the SimpleCommand **class**. Therefore, you can use #{...} to display specific things (like #{sumarized_options}).
|
74
|
-
* Default error handlers are installed by default to catch Interrupt, Quickl::Exit and OptionParser::Error. See error_handling example to learn more about them.
|
data/examples/hello/hello
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path('../../helper', __FILE__)
|
3
|
-
|
4
|
-
#
|
5
|
-
# Say hello
|
6
|
-
#
|
7
|
-
# SYNOPSIS
|
8
|
-
# #{program_name} [--help] [--version] [--capitalize] [WHO]
|
9
|
-
#
|
10
|
-
# OPTIONS
|
11
|
-
# #{summarized_options}
|
12
|
-
#
|
13
|
-
# DESCRIPTION
|
14
|
-
# Without any argument, says hello to the world. When a single argument
|
15
|
-
# is given says hello to the user.
|
16
|
-
#
|
17
|
-
class Hello < Quickl::Command(__FILE__, __LINE__)
|
18
|
-
|
19
|
-
# Command's version
|
20
|
-
VERSION = "0.1.0"
|
21
|
-
|
22
|
-
# Install command options
|
23
|
-
options do |opt|
|
24
|
-
|
25
|
-
# Capitalize user name?
|
26
|
-
opt.on("--capitalize", "-c", "Capitalize user name") do
|
27
|
-
@capitalize = true
|
28
|
-
end
|
29
|
-
|
30
|
-
# Show the help and exit
|
31
|
-
opt.on_tail("--help", "Show help") do
|
32
|
-
raise Quickl::Help
|
33
|
-
end
|
34
|
-
|
35
|
-
# Show version and exit
|
36
|
-
opt.on_tail("--version", "Show version") do
|
37
|
-
raise Quickl::Exit, "#{program_name} #{VERSION} (c) 2010, Bernard Lambeau"
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
# Execute the command on some arguments
|
43
|
-
def execute(args)
|
44
|
-
if args.size <= 1
|
45
|
-
name = args.first || "world"
|
46
|
-
name = name.capitalize if @capitalize
|
47
|
-
puts "Hello #{name}!"
|
48
|
-
else
|
49
|
-
raise Quickl::InvalidArgument, "Useless arguments: #{args.join(' ')}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end # class Hello
|
54
|
-
|
55
|
-
if __FILE__ == $0
|
56
|
-
Hello.run(ARGV, __FILE__)
|
57
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stringio'
|
3
|
-
begin
|
4
|
-
require 'quickl'
|
5
|
-
rescue LoadError
|
6
|
-
$LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
|
7
|
-
require 'quickl'
|
8
|
-
end
|
9
|
-
Kernel.load File.expand_path('../hello', __FILE__)
|
10
|
-
|
11
|
-
class HelloTest < Test::Unit::TestCase
|
12
|
-
|
13
|
-
def assert_exits(match, exit_code)
|
14
|
-
yield
|
15
|
-
assert_false true, "Expected to exit with #{match}, nothing raised"
|
16
|
-
rescue Quickl::Exit => ex
|
17
|
-
assert_equal exit_code, ex.exit_code
|
18
|
-
assert ex.message =~ match
|
19
|
-
end
|
20
|
-
|
21
|
-
def run_command(*args)
|
22
|
-
$stdout = StringIO.new
|
23
|
-
Hello.no_react_to(Quickl::Exit)
|
24
|
-
Hello.run args
|
25
|
-
$stdout.string
|
26
|
-
ensure
|
27
|
-
$stdout = STDOUT
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_normal_runs
|
31
|
-
assert_equal "Hello world!\n", run_command
|
32
|
-
assert_equal "Hello blambeau!\n", run_command("blambeau")
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_capitalize
|
36
|
-
assert_equal "Hello World!\n", run_command("--capitalize")
|
37
|
-
assert_equal "Hello Blambeau!\n", run_command("--capitalize", "blambeau")
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_version_option
|
41
|
-
assert_exits(/(c)/, 0){
|
42
|
-
run_command("--version")
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_help_option
|
47
|
-
assert_exits(/DESCRIPTION/, 0){
|
48
|
-
run_command("--help")
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def test_no_such_option
|
54
|
-
assert_exits(/invalid option/, -1){
|
55
|
-
run_command("--no-such-option")
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_too_many_arguments
|
60
|
-
assert_exits(/Useless arguments/, -1){
|
61
|
-
run_command('hello', 'too')
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/examples/helper.rb
DELETED
data/templates/single.erb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'quickl'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
gem 'quickl'
|
6
|
-
retry
|
7
|
-
end
|
8
|
-
|
9
|
-
#
|
10
|
-
# FIX: overview
|
11
|
-
#
|
12
|
-
# SYNOPSIS
|
13
|
-
# #{command_name} [options] ARGS...
|
14
|
-
#
|
15
|
-
# OPTIONS
|
16
|
-
# #{summarized_options}
|
17
|
-
#
|
18
|
-
# DESCRIPTION
|
19
|
-
# FIX: description
|
20
|
-
#
|
21
|
-
class <%= cmd_class_name %> < Quickl::Command(__FILE__, __LINE__)
|
22
|
-
|
23
|
-
VERSION = "0.1.0"
|
24
|
-
|
25
|
-
# Install options
|
26
|
-
options do |opt|
|
27
|
-
<%= option_helpers.collect{|s| tabto(s,4)}.join("\n") %>
|
28
|
-
end
|
29
|
-
|
30
|
-
# Run the command
|
31
|
-
def execute(args)
|
32
|
-
# FIX: do something here
|
33
|
-
puts "Hello #{args.join(' and ')} from #{program_name}"
|
34
|
-
end
|
35
|
-
|
36
|
-
end # class <%= cmd_class_name %>
|
37
|
-
|
38
|
-
if __FILE__ == $0
|
39
|
-
<%= cmd_class_name %>.run(ARGV)
|
40
|
-
end
|