Class: HaveAPI::GoClient::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/go_client/cli.rb

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/haveapi/go_client/cli.rb', line 6

def self.run
  options = {
    package: 'client'
  }

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] <api url> <destination>"

    opts.on('--version VERSION', 'Use specified API version') do |v|
      options[:version] = v
    end

    opts.on('--module MODULE', 'Name of the generated Go module') do |v|
      options[:module] = v
    end

    opts.on('--package PKG', 'Name of the generated Go package') do |v|
      options[:package] = v
    end
  end

  parser.parse!

  if ARGV.length != 2
    warn 'Invalid arguments'
    puts @global_opt.help
    exit(false)
  end

  g = Generator.new(ARGV[0], ARGV[1], options)
  g.generate
  g.go_fmt
end