4
我正在嘗試使用Thor創建可執行的ruby腳本。Thor讀取配置yaml文件以覆蓋選項
我已經爲我的任務定義了選項。到目前爲止,我有這樣的事情
class Command < Thor
desc "csv2strings CSV_FILENAME", "convert CSV file to '.strings' file"
method_option :langs, :type => :hash, :required => true, :aliases => "-L", :desc => "languages to convert"
...
def csv2strings(filename)
...
end
...
def config
args = options.dup
args[:file] ||= '.csvconverter.yaml'
config = YAML::load File.open(args[:file], 'r')
end
end
當csv2strings
被稱爲不帶參數,我想調用的配置任務,這將設置選項:langs
。
我還沒有找到一個好方法來做到這一點。
任何幫助將不勝感激。
感謝該訣竅!然而,我必須處理'csv2strings'方法選項中的必需選項,方法在所需的檢查後被調用。所以,如果你有任何解決方案來改善,只是讓我知道 – netbe