Sha256: e0e48434e264c5a2814f36783c6e0d8f48b5209aaa7af53b5e727a4d2ff43dad

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

#!/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

if ENV['RUBIKON_DEV']
  require File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'lib', 'rubikon')
else
  require 'rubygems'
  require 'rubikon'
end

# 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
  default 'Simple hello world' do
    debug 'Starting to greet the world...'
    if given? :name
      greet parameters[:name].who
    elsif given? :names
      names.args.each do |name|
        greet name
      end
    else
      greet 'World'
    end
    puts 'Nice to see you.' if given? :more
  end

  # Interactive mode
  #
  # Ask the user for his name and greet him
  command :interactive, 'Greet interactively' do
    name = input 'Please enter your name'
    call :'__default', '--name', name
  end

  # Show a progress bar while iterating through a loop
  flag :brackets
  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
        progress.+
      end
    end
  end

  # Sleep for 5 seconds while displaying a throbber
  command :throbber, 'Display a throbber' do
    put 'Greeting the whole world takes some time... '
    throbber do
      sleep 5
    end
    puts 'done.'
  end

  # A standard Ruby class method for greeting
  def greet(someone)
    puts "Hello #{someone}!"
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubikon-0.5.2 samples/helloworld/hello_world.rb
rubikon-0.5.1 samples/helloworld/hello_world.rb