ruby – 可以在不调用Thor的情况下调用可执行的Thor驱动的脚本吗
发布时间:2020-12-17 04:30:47 所属栏目:百科 来源:网络整理
导读:我有一个基于Thor的 Ruby脚本,但是我想将它作为一个宝石部署在人们的bin目录中,人们可以在不需要做thto mytool的情况下进行打击. 所以相反他们只是使用mytool 这可能吗? 我知道有可能使用vanilla optparse,但如果可能,我宁愿使用Thor. 更新:这是我根据Thor
我有一个基于Thor的
Ruby脚本,但是我想将它作为一个宝石部署在人们的bin目录中,人们可以在不需要做thto mytool的情况下进行打击.
所以相反他们只是使用mytool 这可能吗? 我知道有可能使用vanilla optparse,但如果可能,我宁愿使用Thor. 更新:这是我根据Thor页面上的示例使用的代码,但我收到以下错误: #!/usr/bin/env thor class App < Thor map "-L" => :list desc "install APP_NAME","install one of the available apps" method_options :force => :boolean,:alias => :string def install(name) user_alias = options[:alias] if options.force? # do something end # other code end desc "list [SEARCH]","list all of the available apps,limited by SEARCH" def list(search="") # list everything end end 错误: /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/runner.rb:34:in `method_missing': undefined method `start' for nil:NilClass (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `send' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:22:in `run' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/task.rb:108:in `run' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/invocation.rb:118:in `invoke_task' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor.rb:246:in `dispatch' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/lib/thor/base.rb:389:in `start' from /usr/lib/ruby/gems/1.8/gems/thor-0.14.0/bin/thor:6 from /usr/bin/thor:19:in `load' from /usr/bin/thor:19 解决方法
做shebang线
#!/usr/bin/env ruby 然后在脚本的末尾添加 App.start (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |