首页 > 解决方案 > 在 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.rbHow can I get access to the Dir.getwdvalue of the script.rband not of the example.rb (这是错误的,因为它在 Dir.chdir 中运行)。

我尝试了全局变量等,但它似乎不起作用。

标签: rubybash

解决方案


推荐阅读