admin管理员组文章数量:1312718
I have a working thor command. now I want it wrapped in rake and called rake thereafter, which rake then calls thor.
eg, my thor call:
$ thor my_sample_thor_class:hello friend --from messenger
from: messenger
Hello, friend!
how to i call something like this in rake? (like just replacing thor with rake)
this is my called thor.
require 'thor'
class MySampleThorClass < Thor
desc "hello NAME", "say hello to NAME"
method_option :name, alias: "-n", type: :string, desc: "greet NAME"
method_option :from, default: "whatever"
method_option :message #, default: "just checking :)"
def hello(name="there")
puts "from: #{options[:from]}" if options[:from]
puts "Hello, #{name}!"
puts options[:message] if options[:message]
end
end
this is my calling rake.
require 'thor'
load 'lib/tasks/my_sample_thor_class.thor'
namespace :sample_thor do
desc "Say hello using Thor"
task :say_hello_thor => :environment do |t, args|
ARGV.shift
MySampleThorClass.start ARGV
end
end
checking...
rake -T | grep -i thor
rake sample_thor:say_hello_thor # Say hello using Thor
rake sample_thor:say_hello_thor
Commands:
rake hello NAME # say hello to NAME
rake help [COMMAND] # Describe available commands or one specific command
now invoking just hello.
rake sample_thor:say_hello_thor hello
from: whatever
Hello, there!
rake aborted!
Don't know how to build task 'hello' (See the list of available tasks with `rake --tasks`)
errs but close.
invoking with argument.
rake sample_thor:say_hello_thor hello friend
from: whatever
Hello, friend!
rake aborted!
Don't know how to build task 'hello' (See the list of available tasks with `rake --tasks`)
errs but closer.
invoking with option --from
rake sample_thor:say_hello_thor hello friend --from whoever
invalid option: --from
from there on, it's a merry go round...
本文标签: how to pass arguments and options to rakelike i do in thorStack Overflow
版权声明:本文标题:how to pass arguments and options to rake, like i do in thor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741877715a2402563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论