[英]Is it possible to call Git or other command line tools from inside a Thor script?
我發現在為我的Rails 3應用程序進行git提交之前和之后,我經常運行一系列例行的“清理”任務。
我正在考慮將這些東西放入Thor腳本,但有一點我無法弄清楚是如何使用Thor(或Rake)來調用系統上的其他工具。
是否可以從Thor或Rake腳本中調用git log
類的命令,如果是這樣,那是什么樣的?
謝謝!
掏出來:
result = %x(git log)
puts result
要么
system('git log')
如果你只想將輸出傳遞給終端。
還有grit gem將Git工具抽象為Ruby庫:
require 'grit'
repo = Grit::Repo.new("/path/to/repo")
repo.commits.each do |commit|
puts "#{commit.id}: #{commit.message}"
end
不要忘記那些只是Ruby文件,所以你也可以在那里使用Ruby庫中的所有東西,所以像%x [rm -rf /], system (“rm -rf /”)和`rm -rf這樣的東西/`也可以在這些腳本中訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.