#!/usr/bin/env ruby require File.expand_path('../../helper', __FILE__) # # Say hello # # SYNOPSIS # #{program_name} [--help] [--version] [--capitalize] [WHO] # # OPTIONS # #{summarized_options} # # DESCRIPTION # Without any argument, says hello to the world. When a single argument # is given says hello to the user. # class Hello < Quickl::Command(__FILE__, __LINE__) # Command's version VERSION = "0.1.0" # Install command options options do |opt| # Capitalize user name? opt.on("--capitalize", "-c", "Capitalize user name") do @capitalize = true end # Show the help and exit opt.on_tail("--help", "Show help") do raise Quickl::Help end # Show version and exit opt.on_tail("--version", "Show version") do raise Quickl::Exit, "#{program_name} #{VERSION} (c) 2010, Bernard Lambeau" end end # Execute the command on some arguments def execute(args) if args.size <= 1 name = args.first || "world" name = name.capitalize if @capitalize puts "Hello #{name}!" else raise Quickl::InvalidArgument, "Useless arguments: #{args.join(' ')}" end end end # class Hello if __FILE__ == $0 Hello.run(ARGV, __FILE__) end