rubikon 0.2.1 → 0.3.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/LICENSE +0 -0
- data/README.md +39 -16
- data/Rakefile +29 -16
- data/lib/core_ext/string.rb +16 -0
- data/lib/rubikon/application/base.rb +10 -10
- data/lib/rubikon/application/class_methods.rb +19 -31
- data/lib/rubikon/application/dsl_methods.rb +427 -0
- data/lib/rubikon/application/instance_methods.rb +160 -261
- data/lib/rubikon/command.rb +135 -0
- data/lib/rubikon/exceptions.rb +62 -9
- data/lib/rubikon/flag.rb +56 -0
- data/lib/rubikon/option.rb +30 -0
- data/lib/rubikon/parameter.rb +101 -0
- data/lib/rubikon/progress_bar.rb +23 -12
- data/lib/rubikon/throbber.rb +10 -5
- data/lib/rubikon.rb +14 -3
- data/test/application_tests.rb +60 -73
- data/test/command_tests.rb +102 -0
- data/test/commands/external_command.rb +1 -0
- data/test/flag_tests.rb +40 -0
- data/test/option_tests.rb +75 -0
- data/test/progress_bar_tests.rb +13 -3
- data/test/test_helper.rb +3 -3
- data/test/testapps.rb +64 -0
- data/test/throbber_tests.rb +25 -3
- metadata +64 -19
- data/VERSION.yml +0 -4
- data/lib/rubikon/action.rb +0 -74
- data/test/action_tests.rb +0 -36
- data/test/testapp.rb +0 -64
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -3,10 +3,14 @@ Rubikon
|
|
3
3
|
|
4
4
|
Rubikon is a simple to use, yet powerful Ruby framework for building
|
5
5
|
console-based applications.
|
6
|
+
Rubikon aims to provide an easy to write and easy to read domain-specific
|
7
|
+
language (DSL) to speed up development of command-line applications. With
|
8
|
+
Rubikon it's a breeze to implement applications with only few options as well
|
9
|
+
as more complex programs like RubyGems, Homebrew or even Git.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
|
-
You can install Rubikon using
|
13
|
+
You can install Rubikon using RubyGems. This is the easiest way of installing
|
10
14
|
and recommended for most users.
|
11
15
|
|
12
16
|
$ gem install rubikon
|
@@ -45,27 +49,39 @@ This is done using `default`:
|
|
45
49
|
|
46
50
|
If you run this application it will just print `Hello World!`.
|
47
51
|
|
48
|
-
You can also add command-line options to your appication using `
|
52
|
+
You can also add command-line options to your appication using `command`:
|
49
53
|
|
50
54
|
class MyApplication < Rubikon::Application
|
51
55
|
|
52
|
-
|
56
|
+
command :hello do
|
53
57
|
puts 'Hello World!'
|
54
58
|
end
|
55
59
|
|
56
60
|
end
|
57
61
|
|
58
62
|
This way your application would do nothing when called without options, but it
|
59
|
-
would print `Hello World!` when called using `ruby myapp.rb
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
would print `Hello World!` when called using `ruby myapp.rb hello`. A command
|
64
|
+
is code that is executed when the application is called with the command's name
|
65
|
+
as the first argument - just like RubyGem's `install` or Git's `commit`.
|
66
|
+
|
67
|
+
Another part of Rubikon's DSL are flags and options. Both are parameter types
|
68
|
+
that change the behaviour of the application. While a flag is a parameter
|
69
|
+
without arguments, an option may take one or more additional arguments. Typical
|
70
|
+
examples for flags are `--debug` or `--verbose` (or short `-d` and `-v`).
|
71
|
+
RubyGem's `--version` is an example for an option that requires additional
|
72
|
+
arguments.
|
73
|
+
Flags and options are easily added to your application's commands using
|
74
|
+
Rubikon's DSL:
|
75
|
+
|
76
|
+
flag :more
|
77
|
+
option :name, 2
|
78
|
+
command :hello do
|
79
|
+
...
|
80
|
+
end
|
63
81
|
|
64
|
-
set :dashed_options, false
|
65
82
|
|
66
83
|
Please see the `samples` directory for more in detail sample applications.
|
67
84
|
|
68
|
-
|
69
85
|
**Warning**:
|
70
86
|
|
71
87
|
Rubikon is still in an early development stage. If you want to use it be aware
|
@@ -76,29 +92,32 @@ Contribute section if you want to help making Rubikon better.
|
|
76
92
|
|
77
93
|
* A simple to use DSL
|
78
94
|
* Automatic checks for option arguments
|
79
|
-
*
|
80
|
-
* Built-in methods to
|
95
|
+
* Built-in methods to capture user input
|
96
|
+
* Built-in methods to display progress bars and throbbers
|
81
97
|
|
82
98
|
## Future plans
|
83
99
|
|
100
|
+
* User defined type safety of option arguments
|
84
101
|
* Automatic generation of help screens
|
85
102
|
* Improved error handling
|
86
103
|
* Built-in support for configuration files
|
87
|
-
* Built-in support for colored output
|
104
|
+
* Built-in support for colored output
|
88
105
|
|
89
106
|
## Requirements
|
90
107
|
|
91
108
|
* Linux, MacOS X or Windows
|
92
|
-
* Ruby 1.8.6 or newer
|
109
|
+
* Ruby 1.8.6 or newer (see the [compatibility page][4] in Rubikon's wiki)
|
93
110
|
|
94
111
|
## Contribute
|
95
112
|
|
113
|
+
Rubikon is a open-source project. Therefore you are free to help improving it.
|
96
114
|
There are several ways of contributing to Rubikon's development:
|
97
115
|
|
98
|
-
* Build apps using it and spread the word
|
116
|
+
* Build apps using it and spread the word.
|
99
117
|
* Report problems and request features using the [issue tracker][2].
|
100
118
|
* Write patches yourself to fix bugs and implement new functionality.
|
101
|
-
* Create a Rubikon fork on [GitHub][1] and start hacking.
|
119
|
+
* Create a Rubikon fork on [GitHub][1] and start hacking. Extra points for
|
120
|
+
using GitHubs pull requests and feature branches.
|
102
121
|
|
103
122
|
## About the name
|
104
123
|
|
@@ -107,7 +126,8 @@ relevance in ancient Rome when Julius Caesar crossed that river with his army
|
|
107
126
|
and thereby declared war to the Roman senate. The phrase "to cross the Rubicon"
|
108
127
|
originates from this event.
|
109
128
|
|
110
|
-
You may also see Rubikon as a
|
129
|
+
You may also see Rubikon as a portmanteau word consisting of *"Ruby"* and
|
130
|
+
*"console"*.
|
111
131
|
|
112
132
|
## License
|
113
133
|
|
@@ -121,9 +141,12 @@ file.
|
|
121
141
|
|
122
142
|
## See Also
|
123
143
|
|
144
|
+
* [Rubikon's homepage][3]
|
124
145
|
* [API documentation](http://www.rdoc.info/projects/koraktor/rubikon)
|
125
146
|
* [GitHub project page][1]
|
126
147
|
* [GitHub issue tracker][2]
|
127
148
|
|
128
149
|
[1]: http://github.com/koraktor/rubikon
|
129
150
|
[2]: http://github.com/koraktor/rubikon/issues
|
151
|
+
[3]: http://koraktor.github.com/rubikon
|
152
|
+
[4]: http://github.com/koraktor/rubikon/wiki/Compatibility
|
data/Rakefile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009, Sebastian Staudt
|
4
|
+
# Copyright (c) 2009-2010, Sebastian Staudt
|
5
5
|
|
6
|
-
require 'rake/rdoctask'
|
7
6
|
require 'rake/testtask'
|
8
7
|
|
9
8
|
src_files = Dir.glob(File.join('lib', '**', '*.rb'))
|
@@ -20,31 +19,45 @@ end
|
|
20
19
|
|
21
20
|
begin
|
22
21
|
require 'jeweler'
|
22
|
+
|
23
|
+
gemspec = Gem::Specification.new do |gem|
|
24
|
+
line = File.read('lib/rubikon.rb')[/^\s*VERSION\s*=\s*.*/]
|
25
|
+
gem.version = line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
26
|
+
end
|
27
|
+
|
23
28
|
# Gem specification
|
24
|
-
Jeweler::Tasks.new do |gem|
|
29
|
+
Jeweler::Tasks.new(gemspec) do |gem|
|
25
30
|
gem.authors = ['Sebastian Staudt']
|
26
31
|
gem.email = 'koraktor@gmail.com'
|
27
32
|
gem.description = 'A simple to use, yet powerful Ruby framework for building console-based applications.'
|
28
33
|
gem.date = Time.now
|
34
|
+
gem.files = %w(README.md Rakefile LICENSE) + src_files + test_files
|
35
|
+
gem.has_rdoc = false
|
29
36
|
gem.homepage = 'http://koraktor.github.com/rubikon'
|
30
37
|
gem.name = gem.rubyforge_project = 'rubikon'
|
31
38
|
gem.summary = 'Rubikon - A Ruby console app framework'
|
32
39
|
|
33
|
-
gem.
|
34
|
-
gem.
|
40
|
+
gem.add_development_dependency('jeweler')
|
41
|
+
gem.add_development_dependency('yard')
|
35
42
|
end
|
36
43
|
rescue LoadError
|
37
|
-
puts
|
44
|
+
puts 'You need Jeweler to build the gem. Install it using `gem install jeweler`.'
|
38
45
|
end
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
begin
|
48
|
+
require 'yard'
|
49
|
+
|
50
|
+
# Create a rake task +:doc+ to build the documentation using YARD
|
51
|
+
YARD::Rake::YardocTask.new do |yardoc|
|
52
|
+
yardoc.name = 'doc'
|
53
|
+
yardoc.files = ['lib/**/*.rb', 'LICENSE', 'README.md']
|
54
|
+
yardoc.options = ['--private', '--title', 'Rubikon — API Documentation']
|
55
|
+
end
|
56
|
+
rescue LoadError
|
57
|
+
desc 'Generate YARD Documentation (not available)'
|
58
|
+
task :doc do
|
59
|
+
puts 'You need YARD to build the documentation. Install it using `gem install yard`.'
|
60
|
+
end
|
48
61
|
end
|
49
62
|
|
50
63
|
# Task for cleaning documentation and package directories
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2010, Sebastian Staudt
|
5
|
+
|
6
|
+
unless String.method_defined?(:start_with?)
|
7
|
+
|
8
|
+
class String
|
9
|
+
|
10
|
+
def start_with?(start)
|
11
|
+
!/^#{start}/.match(self).nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009, Sebastian Staudt
|
4
|
+
# Copyright (c) 2009-2010, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'singleton'
|
7
7
|
require 'yaml'
|
8
8
|
|
9
|
-
require 'rubikon/action'
|
10
9
|
require 'rubikon/application/class_methods'
|
10
|
+
require 'rubikon/application/dsl_methods'
|
11
11
|
require 'rubikon/application/instance_methods'
|
12
|
-
require 'rubikon/exceptions'
|
13
12
|
|
14
13
|
module Rubikon
|
15
14
|
|
16
|
-
version = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', '..', 'VERSION.yml'))
|
17
|
-
VERSION = "#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
|
18
|
-
|
19
15
|
module Application
|
20
16
|
|
21
|
-
# The main class of Rubikon. Let your own application class inherit from
|
22
|
-
# one.
|
17
|
+
# The main class of Rubikon. Let your own application class inherit from
|
18
|
+
# this one.
|
19
|
+
#
|
20
|
+
# @author Sebastian Staudt
|
21
|
+
# @since 0.2.0
|
23
22
|
class Base
|
24
23
|
|
25
24
|
class << self
|
26
25
|
include Rubikon::Application::ClassMethods
|
27
26
|
end
|
28
27
|
|
28
|
+
include Rubikon::Application::DSLMethods
|
29
29
|
include Rubikon::Application::InstanceMethods
|
30
30
|
include Singleton
|
31
31
|
|
@@ -1,27 +1,34 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009, Sebastian Staudt
|
4
|
+
# Copyright (c) 2009-2010, Sebastian Staudt
|
5
5
|
|
6
6
|
module Rubikon
|
7
7
|
|
8
8
|
module Application
|
9
9
|
|
10
|
+
# This module contains all class methods of +Application::Base+ and its
|
11
|
+
# subclasses.
|
12
|
+
#
|
13
|
+
# @author Sebastian Staudt
|
14
|
+
# @see Application::Base
|
15
|
+
# @since 0.2.0
|
10
16
|
module ClassMethods
|
11
17
|
|
12
18
|
private
|
13
19
|
|
14
|
-
# Returns whether this application should be
|
20
|
+
# Returns whether this application should be run automatically
|
15
21
|
def autorun?
|
16
22
|
instance.instance_variable_get(:@settings)[:autorun] || false
|
17
23
|
end
|
18
24
|
|
19
25
|
# Enables autorun functionality using <tt>Kernel#at_exit</tt>
|
20
26
|
#
|
21
|
-
#
|
22
|
-
#
|
27
|
+
# <em>This is called automatically when subclassing
|
28
|
+
# Application::Base.</em>
|
23
29
|
#
|
24
|
-
#
|
30
|
+
# @param [Class] subclass The subclass inheriting from Application::Base.
|
31
|
+
# This is the user's application.
|
25
32
|
def inherited(subclass)
|
26
33
|
super
|
27
34
|
Singleton.__init__(subclass)
|
@@ -31,35 +38,16 @@ module Rubikon
|
|
31
38
|
# This is used for convinience. Method calls on the class itself are
|
32
39
|
# relayed to the singleton instance.
|
33
40
|
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# +block+:: A block that may be given to the method
|
41
|
+
# <em>This is called automatically when calling methods on the
|
42
|
+
# application class.</em>
|
37
43
|
#
|
38
|
-
#
|
44
|
+
# @param [Symbol] method_name The name of the method being called
|
45
|
+
# @param [Array] args Any arguments that are given to the method
|
46
|
+
# @param [Proc] block A block that may be given to the method
|
39
47
|
def method_missing(method_name, *args, &block)
|
40
48
|
instance.send(method_name, *args, &block)
|
41
49
|
end
|
42
50
|
|
43
|
-
# Relay putc to the instance method
|
44
|
-
#
|
45
|
-
# This is used to hide <tt>Kernel#putc</tt> so that the Application's
|
46
|
-
# output IO object is used for printing text
|
47
|
-
#
|
48
|
-
# +text+:: The text to write into the output stream
|
49
|
-
def putc(text)
|
50
|
-
instance.putc text
|
51
|
-
end
|
52
|
-
|
53
|
-
# Relay puts to the instance method
|
54
|
-
#
|
55
|
-
# This is used to hide <tt>Kernel#puts</tt> so that the Application's
|
56
|
-
# output IO object is used for printing text
|
57
|
-
#
|
58
|
-
# +text+:: The text to write into the output stream
|
59
|
-
def puts(text)
|
60
|
-
instance.puts text
|
61
|
-
end
|
62
|
-
|
63
51
|
end
|
64
52
|
|
65
53
|
end
|