ruby - 在 thor 任务中访问 PWD
问题描述
在我的主要雷神文件中,我称此代码为
脚本.rb
# this works
current_dir = Dir.getwd
# this changes directory into the tasks
Dir.chdir(#{pwd}/tasks) {
IO.popen("thor #{ARGV * ' '}") do |io|
while (line = io.gets) do
puts line
end
io.close
end
}
任务/example.rb
require 'thor'
class Git < Thor
include Thor::Actions
desc 'test', 'test'
def test
puts Dir.getwd # this is showing my tasks folder
end
end
Inside example.rb
How can I get access to the Dir.getwd
value of the script.rb
and not of the example.rb
(这是错误的,因为它在 Dir.chdir 中运行)。
我尝试了全局变量等,但它似乎不起作用。
解决方案
推荐阅读
- android - 找不到满足版本约束的“androidx.arch.core:core-common”版本
- dll - 使用 ilmerge 命令提示符将 exe 与 dll 合并后,从 exe 开始
- c# - 如何统一使用简单 JSON 从数组数组中获取图像 URL?
- unity3d - 遮挡剔除和遮挡处理有什么区别?
- javascript - 有没有办法从持续更新的文件中读取仅在 nodejs 中的新更新
- java - IntelliJ 中最常用的字符串
- mysql-workbench - mysql工作台没有与aws aurora serverless mysql连接
- pdf - 运行 gulp 任务“buildFonts”以导出带有 HTML 图标的 PDF 时出现问题
- python - VSCode Python 调试器 FileNotFoundError
- java - 用于完成 CheckpointMark 的 Beam 模型合同