poy*_*ode 11 ruby command-line-interface command-line-arguments thor
my_gem你好name1 name2 name3给我一个
my_gem hello至少需要一个参数:my_gem hello name
我应该解析它们并用分隔符分隔参数吗?
例如
my_gem hello name1,name2,name3,nameN
在文件中它看起来像
class MyCLI < Thor
desc "hello NAMES", "say hello to names"
def hello(names)
say "hello #{names.split(',')}"
end
end
Run Code Online (Sandbox Code Playgroud)
或者无论如何要做到这一点?
Dr.*_*rer 15
是的,有另一种方法可以做到这一点.
require 'thor'
class TestApp < Thor
desc "hello NAMES", "long desc"
def hello(*names)
say "hello #{names.join('; ')}"
end
end
Run Code Online (Sandbox Code Playgroud)
它可以像这样调用:
$ thor test_app:hello first second third
hello first; second; third
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3522 次 |
| 最近记录: |