# Support libraries require 'rbconfig' require 'facets' require 'consoleapp' #require 'console/command' require 'reap/reap' class ReapCommand < Console::Command # to do first for every task #def command_setup # $PROJECT_INFO = ProjectInfo.new( $PROJECT_FILE ) #end # Options # verbose mode def __verbose ; $VERBOSE = true ; end alias_method :_V, :__verbose # option to display help def __force ; $FORCE = true ; end alias_method :_f, :__force # pretend mode (under construction) def __pretend; $PRETEND = true ; end alias_method :_P, :__pretend # debug mode (under construction) def __debug; $DEBUG = true ; end alias_method :_D, :__debug def __password( pass ); $PASSWORD = pass ; end alias_method :_p, :__password # display reap version def __version ; version ; end alias_method :_v, :__version # option to display help def __help ; help ; end alias_method :_h, :__help # option to display tasks def __tasks; tasks ; end alias_method :_t, :__tasks #option for build version (only for package task) def _b ; $BUILD_VERSION = true ; end #def _f( pif ) ; $PROJECT_FILE = pif ; end #alias_method :_f, :__file # default action def default tasks end # display version def version puts "Reap v#{Reap::Version}" exit 0 end # display help def help(tsk=nil) if tsk t = Reap.application.tasks[tsk] unless t puts "Unknown task '#{tsk}'." exit 0 end s = "\n" s << "#{args[0]}: " s << t.task_desc.sub(/^\n+/, '').rstrip s << "\n\n" if thelp = t.task_help s << thelp.sub(/^\n+/, '').rstrip end s << "\n\n" puts s else puts HELP end exit 0 end # list available tasks def tasks app = Reap.application tasklist = [] if app.tasks.empty? puts "No tasks available." else sorted = app.tasks.keys.sort margin = sorted.collect{ |t| t.size }.max + 6 sorted.each do |name| tasklist << " #{name}".ljust(margin) + "#{app.tasks[name].task_desc}" end puts "(#{Dir.pwd})" puts puts tasklist.join("\n") puts end end #alias_method :ls, :tasks # Add all the reap tasks. app = Reap.application app.tasks.each do |name, task| define_method(name) { |*args| #puts "(#{Dir.pwd})" task.execute( *args ) } end end HELP = <<-HERE reap [options...] [arguments...] COMMANDS: tasks List all the current tasks with descriptions. (This is the default if no command is given.) help [task] Displays this help information. If a task name is given, it will provide help information specific to that task. OPTIONS: -h --help Display this help information. -v --version Display the current version. -V --verbose Provides extra verbose processing information. -f --force Forces certain operations to be performed. -D --debug Provides extra verbose processing information. -f --file Specify alternate project file. HERE