samples/helloworld/hello_world.rb in rubikon-0.5.3 vs samples/helloworld/hello_world.rb in rubikon-0.6.0
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
#
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
-# Copyright (c) 2010, Sebastian Staudt
+# Copyright (c) 2010-2011, Sebastian Staudt
if ENV['RUBIKON_DEV']
require File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'lib', 'rubikon')
else
require 'rubygems'
@@ -14,24 +14,28 @@
# A relatively simple Hello World application using Rubikon
class HelloWorld < Rubikon::Application::Base
# Greet the whole world per default
- flag :more
- option :name, [:who]
- option :names, -1
+ flag :more, 'Display more information while greeting'
+ option :name, 'A single name to greet', :who
+ option :names, 'One or more names to greet', :who => :remainder
+ option :special, 'A special name', :who => ['Guybrush', /LeChuck/, :numeric]
default 'Simple hello world' do
debug 'Starting to greet the world...'
if given? :name
- greet parameters[:name].who
+ names = [who]
elsif given? :names
- names.args.each do |name|
- greet name
- end
+ names = who
+ elsif given? :special
+ names = [who]
else
- greet 'World'
+ names = %w{World}
end
+
+ names.each { |name| greet name }
+
puts 'Nice to see you.' if given? :more
end
# Interactive mode
#
@@ -40,10 +44,10 @@
name = input 'Please enter your name'
call :__default, '--name', name
end
# Show a progress bar while iterating through a loop
- flag :brackets
+ flag :brackets, 'Show brackets around the progress bar'
command :progress, 'Display a progress bar' do
put 'Watch my progress while I greet the world: '
x = 1000000
progress_bar(:char => '+', :maximum => x, :size => 30, :brackets => brackets.given?, :bracket_filler => '-') do |progress|
x.times do