是否可以在Thor中为命令创建别名?
就像命令混入指挥官一样。https://github.com/tj/commander#command-aliasing
我可以为选项找到别名,但不能找到命令本身的别名。
用托尔的例子,
#!/usr/bin/env ruby
require 'thor'
# cli.rb
class MyCLI < Thor
desc "hello NAME", "say hello to NAME"
def hello(name)
puts "Hello #{name}"
end
end
MyCLI.start(ARGV)我应该能跑
$ ./cli.rb hello John
Hello John我也想把命令"hello“别名为"hi”。
发布于 2015-02-13 16:52:25
您可以为此使用map:
method
#!/usr/bin/env ruby
require 'thor'
# cli.rb
class MyCLI < Thor
desc "hello NAME", "say hello to NAME"
def hello(name)
puts "Hello #{name}"
end
map hi: :hello
end
MyCLI.start(ARGV)发布于 2015-02-14 15:20:17
使用method_option作为别名。
#!/usr/bin/env ruby
require 'thor'
# cli.rb
class MyCLI < Thor
desc "hello NAME", "say hello to NAME"
method_option :hello , :aliases => "-hello" , :desc => "Hello Command"
def hello(name)
puts "Hello #{name}"
end
end
MyCLI.start(ARGV)https://stackoverflow.com/questions/28504373
复制相似问题