require 'rbconfig' require 'fileutils' require 'facets' # Next two may be moved in the future to: require 'command' # 'console/command' require 'ansicode' # 'console/ansicode' require 'string/tabto' require 'gem/self/gempath' require 'reap/reap' # ReapCommand is the CLI interface to Reap. class ReapCommand < Console::Command INFO_FILES = [ 'ProjectInfo', 'projectinfo' ] # Options # verbose mode def __verbose ; $VERBOSE = true ; end alias_method :_V, :__verbose # force mode def __force ; $FORCE = true ; end alias_method :_f, :__force # pretend mode (under construction) #-- # A few tasks have some support for pretending # but this has to be developed much more # before it can be commonly avaialble. # Notice it is not mentioned in the Help. #++ 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 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 subcommand is to display tasks. def default tasks end # Display version. def version puts "Reap v#{Reap::Version}" exit 0 # shortcuts execution when called via the --version option. end # Display help. def help puts HELP exit 0 # shortcuts execution when called via the --help option. end # list available tasks def tasks # TODO How to deal with windows or other ansi not support? hi = Console::ANSICode.bold #+ Console::ANSICode.yellow lo = Console::ANSICode.reset #+ Console::ANSICode.blue re = Console::ANSICode.reset tasklist = TaskSpace.visible_tasks if tasklist.empty? puts "No tasks available." else sorted = tasklist.collect{ |e| e.to_s }.sort outlist = [] margin = sorted.collect{ |t| t.size }.max + 2 sorted.each do |name| outlist << hi + " #{name}".ljust(margin) + lo + " #{TaskSpace.instance_task(name).description}" + re end puts "[from #{Dir.pwd}]" #puts puts outlist.join("\n") #puts end end # Command shows task dependencies. def prerequisite Reap.tasks.each { |name, t| print name print " => " puts TaskSpace.instance_task(name.to_sym).prerequisite.inspect } end # Define a CLI callable method for each described tasks. # # NOTE The use of the launcher class seems a touch hackish, # and indicates to me that there might be a better # way to organize the tasks, but as long as it works! launcher = Class.new{ include TaskSpace }.new() TaskSpace.visible_tasks.each do |t| define_method(t) do |*args| launcher.send(t, *args) end end # Help text HELP = <<-HERE.tabto(2) reap [options...] [arguments...] COMMANDS: tasks List all the current tasks with descriptions. (This is the default if no command is given.) help [type] Displays this help information. If a task type is given, it will provide help information specific to that kind of 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 #-- # # HELP = <<-HERE.tabto(2) # # reap [options...] [arguments...] # # COMMANDS: # # tasks # List all the current tasks with descriptions. # (This is the default if no command is given.) # # scaffold [type] # Generates a project directory layout within the current # directory. For more details type 'reap help scaffold'. # # template | projectinfo # Create a ProjectInfo template file in the current directory # Unlike 'scaffold', this is especially useful for pre-existing # projects. # # help [type] # Displays this help information. If a task type is given, it # will provide help information specific to that kind of 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 # # HELP_SCAFFOLD = <<-HERE.tabto(2) # # reap scaffold [type] # # Generates a project directory layout within the current # directory. The scaffolding includes all the standard # features such as directories lib/ bin/ doc/ and files # like README. # # To use this task you should first create an empty # directory and than change into it. This command will # not create a new project directory. As a safegaurd, this # command will not generate scaffolding in a directory with # files already present, unless you use the -f (force) option. # # There are currently two types of supported scaffoldings: # 'standard', which is the default if no type is given, # and 'subversion' which creates a "trunk" hierarchy. # # HERE # # HELP_TEMPLATE = <<-HERE.tabto(2) # # reap template | reap projectinfo # # Create a ProjectInfo template file in the current directory # Unlike 'scaffold', this is especially useful for pre-existing # projects. # # HERE # #++ end