简体   繁体   English

使用rubyguard gem监视c ++文件

[英]Using ruby guard gem to monitor c++ files

I'm using this Guardfile to watch .cpp and .h files and fire off make if anything changes. 我正在使用此Guardfile来监视.cpp和.h文件,如果有任何更改,请启动make。 Works great as long as all files are in the directory the Guardfile is in. 只要所有文件都在Guardfile所在的目录中,它就可以很好地工作。

guard 'shell' do
    watch(%r{^\w*\.(h|cpp)$}) do
        `make test` 
    end
end

I'd like to have the Guardfile in the root directory of my project tree and monitor the .h and .cpp files in each subdirectory. 我想将Guardfile放在项目树的根目录中,并监视每个子目录中的.h和.cpp文件。 Is it possible to do that by changing the regex, or do I have to have a Guardfile in each subdirectory? 是否可以通过更改正则表达式来做到这一点,还是必须在每个子目录中都有一个Guardfile?

(Not sure why the formatting doesn't go through correctly) (不确定为什么格式化不正确)

You have to install the following two gems: 您必须安装以下两个gem:

guard
guard-shell

Create a Guardfile in the directory where you want to watch the files 在您要观看文件的目录中创建一个Guardfile

guard 'shell' do 
  watch(%r{^.+\.(h|hpp|cpp)$}) do 
    `make test`
  end 
end

Important that the actual shell command (here: make test ) has to be wrapped in ` ` 重要的是实际的shell命令(在这里: make test )必须包装在``中

Then run: > guard 然后运行: > guard

You should be able to of this through the regex. 您应该能够通过正则表达式做到这一点。 Try this: 尝试这个:

guard 'shell' do 
  watch(%r{^.+\.(h|cpp)$}) do 
    make test 
  end 
end

This should match files in any directory below the root directory of your app with the extensions .cpp or .h. 这应匹配应用程序根目录下任何扩展名为.cpp或.h的目录中的文件。 If you want to focus to a sub-directory try ^dir/sub/.+\\.(h|cpp)$ 如果要集中到子目录,请尝试^dir/sub/.+\\.(h|cpp)$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM