Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Last active December 14, 2015 01:49
Show Gist options
  • Select an option

  • Save jimweirich/5009198 to your computer and use it in GitHub Desktop.

Select an option

Save jimweirich/5009198 to your computer and use it in GitHub Desktop.
How Rake runs its top level.
# Sample custom rake-like command supporting three options.
#
# mycmd start
# mycmd stop
# mycmd restart
require 'rake'
Rake.application.init('mycmd')
task :start do ... end
task :stop do ... end
task :restart do ... end
Rake.application.top_level
# Snippet of code from Rake/application.rb ...
# Run the Rake application. The run method performs the following
# three steps:
#
# * Initialize the command line options (+init+).
# * Define the tasks (+load_rakefile+).
# * Run the top level tasks (+top_level+).
#
# If you wish to build a custom rake command, you should call
# +init+ on your application. Then define any tasks. Finally,
# call +top_level+ to run your top level tasks.
#
def run
standard_exception_handling do
init
load_rakefile
top_level
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment