mohangk.org/blog

Thoughts, somewhat explained

Capistrano::CLI.ui.ask – setting a default value if left blank

| 0 comments

In trying to make some of my Capistrano tasks configurable yet having sensible defaults, I was looking for a way to set default values if the user presses enter without keying in any values for the Capistrano::CLI.ui.ask prompt. Turns out the “ask” method actually comes from a different project, HighLine. Looking at that docs provided the answer, example below.

#allows you to key in a date in YYYY-MM-DD format, if nothing is provided, defaults to todays date.

set(:dump_date) do
Capistrano::CLI.ui.ask(“Enter date forĀ  dump: “) {|q| q.default = “#{Date.today.year}-#{Date.today.month}-#{sprintf(‘%02d’,Date.today.day)}” }
end

Leave a Reply

Required fields are marked *.

*