कमांड लाइन पर थोर कमांड को कॉल करते समय, नामों को उनके मॉड्यूल/क्लास स्ट्रक्चर द्वारा नामित किया गया है, उदाहरण के लिए नामांकनस्टैंडअलोन रूबी निष्पादन योग्य
class App < Thor
desc 'hello', 'prints hello'
def hello
puts 'hello'
end
end
कमांड के साथ चलाया जाएगा
thor app:hello
हालांकि, अगर आप आप की तरह आदेश चला सकते हैं तल पर
App.start
रख कर कि स्वयं निष्पादन योग्य बनाने:
app hello
क्या एन के लिए कोई रास्ता है उन आदेशों का पालन करें?
#!/usr/bin/env ruby
require "rubygems"
require "thor"
class Say < Thor
# ./app say:hello
desc 'hello', 'prints hello'
def hello
puts 'hello'
end
end
class App < Thor
# ./app nothing
desc 'nothing', 'does nothing'
def nothing
puts 'doing nothing'
end
end
begin
parts = ARGV[0].split(':')
namespace = Kernel.const_get(parts[0].capitalize)
parts.shift
ARGV[0] = parts.join
namespace.start
rescue
App.start
end
भी आदर्श नहीं या,:: तो है कि आप उदाहरण के लिए, कह सकते हैं
app say:hello
app say:goodbye
पवित्र बकवास! आप मेरे जीवन के 8 घंटे पहले कहाँ थे? सुरुचिपूर्ण समाधान के लिए धन्यवाद। – elmt
यह मेरे लिए काम नहीं करता था (thor 0.18.1) लेकिन https://github.com/wycats/thor/issues/261#issuecomment-16880836 पर वर्णित एक समान काम काम किया –