为了让我更容易地debugging我的提供者,我有时想在自己的ruby代码中使用'command'。
试图弄清楚如何是问题。
这就是我在提供者中使用它的方式:
commands :wget => '/usr/bin/wget', :cp => '/bin/cp'
后来,我可以用简单的命令来运行命令:
wget('http://example.com')
现在,我试着这样做:
something = Puppet::Provider.commands({:wget => '/usr/bin/wget'}) something.wget('http://example.com')
但是,我得到这个:
test.rb:15: undefined method `wget' for {:wget=>"/usr/bin/wget"}:Hash (NoMethodError)
我也试过运行:
wget = Puppet::Provider::Command.new('wget', '/usr/bin/wget', Puppet::Util, Puppet::Util::Execution) puts Puppet::Util::Execution.execute(['wget','http://example.com'],{})
但输出是空白的…
有任何想法吗?
我不相信这是可行的。
命令方法依赖于另一个Provider类方法 ,它最终使用meta_def来创build方法,然后在Provider类中使用该方法。
所以这个function只适用于Puppet::Provider实际子类。
我认为做这个工作的最好的一步就是把整个function放到一个混合模块中, Provider类将会extend 。 那么你自己的class级也可以这样做。 (不知道这是否真的能在Puppet中运行)