rubikon 0.5.0 → 0.5.1
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/README.md +1 -0
- data/lib/rubikon/application/dsl_methods.rb +28 -26
- data/lib/rubikon/application/instance_methods.rb +12 -8
- data/lib/rubikon/application/sandbox.rb +1 -1
- data/lib/rubikon/progress_bar.rb +1 -0
- data/lib/rubikon.rb +1 -1
- data/samples/helloworld/hello_world.rb +0 -5
- data/test/test_application.rb +8 -0
- metadata +6 -6
data/README.md
CHANGED
@@ -16,9 +16,11 @@ module Rubikon
|
|
16
16
|
# @since 0.3.0
|
17
17
|
module DSLMethods
|
18
18
|
|
19
|
-
# @return [String] The (first)
|
19
|
+
# @return [String] The (first) file where the application has been
|
20
|
+
# defined
|
20
21
|
attr_reader :base_file
|
21
22
|
|
23
|
+
# @return [Hash] The active configuration of the application
|
22
24
|
attr_reader :config
|
23
25
|
|
24
26
|
# @return [String] The absolute path of the application
|
@@ -26,6 +28,26 @@ module Rubikon
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
31
|
+
# Checks whether parameter with the given name has been supplied by the
|
32
|
+
# user on the command-line.
|
33
|
+
#
|
34
|
+
# @param [#to_sym] name The name of the parameter to check
|
35
|
+
# @since 0.2.0
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# flag :status
|
39
|
+
# command :something do
|
40
|
+
# print_status if active? :status
|
41
|
+
# end
|
42
|
+
def active?(name)
|
43
|
+
name = name.to_sym
|
44
|
+
parameter = @global_parameters[name]
|
45
|
+
parameter = @current_command.parameters[name] if parameter.nil?
|
46
|
+
return false if parameter.nil?
|
47
|
+
parameter.send(:active?)
|
48
|
+
end
|
49
|
+
alias_method :given?, :active?
|
50
|
+
|
29
51
|
# Call another named command with the given arguments
|
30
52
|
#
|
31
53
|
# @param [Symbol] command_name The name of the command to call
|
@@ -106,11 +128,11 @@ module Rubikon
|
|
106
128
|
#
|
107
129
|
# @return [Command] The default Command object
|
108
130
|
# @since 0.2.0
|
109
|
-
def default(description = nil, &block)
|
110
|
-
if
|
111
|
-
command({ :__default =>
|
131
|
+
def default(arg_count = nil, description = nil, &block)
|
132
|
+
if arg_count.is_a? Symbol
|
133
|
+
command({ :__default => arg_count })
|
112
134
|
else
|
113
|
-
command(:__default, description, &block)
|
135
|
+
command(:__default, arg_count, description, &block)
|
114
136
|
end
|
115
137
|
end
|
116
138
|
|
@@ -139,26 +161,6 @@ module Rubikon
|
|
139
161
|
end
|
140
162
|
end
|
141
163
|
|
142
|
-
# Checks whether parameter with the given name has been supplied by the
|
143
|
-
# user on the command-line.
|
144
|
-
#
|
145
|
-
# @param [#to_sym] name The name of the parameter to check
|
146
|
-
# @since 0.2.0
|
147
|
-
#
|
148
|
-
# @example
|
149
|
-
# flag :status
|
150
|
-
# command :something do
|
151
|
-
# print_status if active? :status
|
152
|
-
# end
|
153
|
-
def active?(name)
|
154
|
-
name = name.to_sym
|
155
|
-
parameter = @global_parameters[name]
|
156
|
-
parameter = @current_command.parameters[name] if parameter.nil?
|
157
|
-
return false if parameter.nil?
|
158
|
-
parameter.send(:active?)
|
159
|
-
end
|
160
|
-
alias_method :given?, :active?
|
161
|
-
|
162
164
|
# Create a new flag with the given name to be used globally
|
163
165
|
#
|
164
166
|
# Global flags are not bound to any command and can therefore be used
|
@@ -398,7 +400,7 @@ module Rubikon
|
|
398
400
|
#
|
399
401
|
# @param [String] text The text to write into the output stream
|
400
402
|
# @since 0.2.0
|
401
|
-
def puts(text)
|
403
|
+
def puts(text = nil)
|
402
404
|
ostream.puts text
|
403
405
|
end
|
404
406
|
|
@@ -60,7 +60,7 @@ module Rubikon
|
|
60
60
|
:raise_errors => false
|
61
61
|
}
|
62
62
|
|
63
|
-
|
63
|
+
@settings[:config_paths] = []
|
64
64
|
if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
|
65
65
|
@settings[:config_paths] << ENV['ALLUSERSPROFILE']
|
66
66
|
else
|
@@ -110,7 +110,7 @@ module Rubikon
|
|
110
110
|
raise $! if @settings[:raise_errors]
|
111
111
|
|
112
112
|
puts "r{Error:}\n #{$!.message}"
|
113
|
-
puts "
|
113
|
+
puts " at #{$!.backtrace.join("\n at ")}" if $DEBUG
|
114
114
|
exit 1
|
115
115
|
ensure
|
116
116
|
InstanceMethods.instance_method(:reset).bind(self).call
|
@@ -299,19 +299,23 @@ module Rubikon
|
|
299
299
|
# parameters of this command that have been supplied and any
|
300
300
|
# additional command-line arguments supplied
|
301
301
|
def parse_arguments(args)
|
302
|
-
command_arg = args.
|
303
|
-
command_arg
|
304
|
-
|
305
|
-
if command_arg.nil?
|
302
|
+
command_arg = args.shift
|
303
|
+
if command_arg.nil? || command_arg.start_with?('-')
|
306
304
|
command = @commands[:__default]
|
305
|
+
args.unshift(command_arg) unless command_arg.nil?
|
307
306
|
raise NoDefaultCommandError if command.nil?
|
308
307
|
else
|
309
308
|
command = @commands[command_arg.to_sym]
|
310
|
-
args.delete_at args.find_index(command_arg)
|
311
309
|
raise UnknownCommandError.new(command_arg) if command.nil?
|
312
310
|
end
|
313
311
|
|
314
|
-
args.
|
312
|
+
args = args.map do |arg|
|
313
|
+
if !arg.start_with?('--') && arg.start_with?('-') && arg.size > 2
|
314
|
+
arg[1..-1].split('').map { |a| "-#{a}"}
|
315
|
+
else
|
316
|
+
arg
|
317
|
+
end
|
318
|
+
end.flatten
|
315
319
|
|
316
320
|
parameter = nil
|
317
321
|
parameters = []
|
data/lib/rubikon/progress_bar.rb
CHANGED
data/lib/rubikon.rb
CHANGED
@@ -15,16 +15,11 @@ end
|
|
15
15
|
# A relatively simple Hello World application using Rubikon
|
16
16
|
class HelloWorld < Rubikon::Application::Base
|
17
17
|
|
18
|
-
set :config_file, 'helloworld.ini'
|
19
|
-
set :config_format, :ini
|
20
|
-
|
21
18
|
# Greet the whole world per default
|
22
19
|
flag :more
|
23
20
|
option :name, [:who]
|
24
21
|
option :names, -1
|
25
22
|
default 'Simple hello world' do
|
26
|
-
p config
|
27
|
-
|
28
23
|
debug 'Starting to greet the world...'
|
29
24
|
if given? :name
|
30
25
|
greet parameters[:name].who
|
data/test/test_application.rb
CHANGED
@@ -159,6 +159,14 @@ class TestApplication < Test::Unit::TestCase
|
|
159
159
|
assert_equal "pre init\npost init\npre execute\nexecute\npost execute\n", @ostream.string
|
160
160
|
end
|
161
161
|
|
162
|
+
should 'allow combining single character parameters' do
|
163
|
+
@app.run(%w{-dv})
|
164
|
+
assert $DEBUG
|
165
|
+
assert $VERBOSE
|
166
|
+
$DEBUG = false
|
167
|
+
$VERBOSE = false
|
168
|
+
end
|
169
|
+
|
162
170
|
end
|
163
171
|
|
164
172
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubikon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sebastian Staudt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -115,8 +115,8 @@ homepage: http://koraktor.github.com/rubikon
|
|
115
115
|
licenses: []
|
116
116
|
|
117
117
|
post_install_message:
|
118
|
-
rdoc_options:
|
119
|
-
|
118
|
+
rdoc_options: []
|
119
|
+
|
120
120
|
require_paths:
|
121
121
|
- lib
|
122
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|