Create a CLI with Thor for a gem

时间:2018-06-04 17:28:12

标签: ruby rubygems command-line-interface bundler thor

I'm creating a gem that gives the weather connecting to APIs, i also created tests and class methods, now i want to add a command line interpreter (CLI).

As the bundler site tutorial for create gem, i'm trying to do it with Thor

I have this in /bin/wizer file

#!/usr/bin/env bash

require "wizer/cli"

Wizer::CLI.start

This in /lib/wizer/cli.rb

require 'thor'
require 'wizer'
module Wizer
  class CLI < Thor
    desc "hello world", "my first cli"
    def self.hello
      "Hello world"
    end
  end
end

this on wizer.gemspec file

  spec.add_runtime_dependency "thor"

And this on Gemfile

gem "thor"

See full gem here

1 个答案:

答案 0 :(得分:1)

这里的主要问题是Ruby不解释getServices文件。而是使用了Bash,它无法处理Ruby代码(或其他任何不像Bourne的shell脚本)。

要解决此问题,请将shebang行(即以bin/wizer开头的文件中的第一行)更改为以下内容:

#!