Going beyond typing cap deploy

I mentioned earlier that if you don't use Capistrano too much, you might not be aware it's designed in such a way that it can be called happily from within Ruby code as well as being called on the command line.

In fact, the snippets below from the rdoc pages for the project, given idea of what's going on under the hood, when you call cap deploy.

Here's the command when we call it straight from the command line, within a capified project:

`cap deploy update_code -vvvv` 

Now here's the same command, wrapped with a very lightweight ruby sprinkling of ruby, that wouldn't need us to supply any command line arguments ourselves.

require 'capistrano/cli'
  Capistrano::CLI.parse(%w(-vvvv -r config/deploy update_code)).execute!

There's a whole lot of clever stuff happening when the capistrano/cli.rb is called, like instantiating a configuration object that stores the arguments for parsing, and serves as a base for other methods, tasks and even full-on recipes to be attached to.

The snippet above is roughly equivalent to the code below, if we wanted to be explicit bout what how we wanted things to be done.

  require 'capistrano'
  require 'capistrano/cli'
  config = Capistrano::Configuration.new
  config.logger_level = Capistrano::Logger::TRACE
  config.set(:password) { Capistrano::CLI.password_prompt }
  config.load "config/deploy"

While writing this post, I consulted the Capistrano docs on rdoc.info repeatedly, and I think at long last, I'm starting to see the appeal of Yard for documentation now. Now to find a fun little project to actually try it out on...

Copyright © 2020 Chris Adams
Powered by Cryogen
Theme by KingMob