是否可以进行交互式 Rake 任务? [英] Is it possible to make an interactive Rake task?

查看:40
本文介绍了是否可以进行交互式 Rake 任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个要求用户输入的 Rake 任务.

I want to run a Rake task that asks the user for input.

我知道我可以在命令行上提供输入,但我想询问用户是否确定他们想要继续执行特定操作,以防他们输入错误的值之一到 Rake 任务.

I know that I can supply input on the command line, but I want to ask the user if they are sure they want to proceed with a particular action in case they mistyped one of the values supplied to the Rake task.

推荐答案

这样的事情可能会奏效

task :action do
  STDOUT.puts "I'm acting!"
end

task :check do
  STDOUT.puts "Are you sure? (y/n)"
  input = STDIN.gets.strip
  if input == 'y'
    Rake::Task["action"].reenable
    Rake::Task["action"].invoke
  else
    STDOUT.puts "So sorry for the confusion"
  end
end

如何重新启用和调用任务从 Rake 任务中运行 Rake 任务?

这篇关于是否可以进行交互式 Rake 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆