Module: Gutsy::Cli

Defined in:
lib/gutsy/cli.rb,
lib/gutsy/generator.rb

Defined Under Namespace

Classes: Generator

Class Method Summary collapse

Class Method Details

.generate(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gutsy/cli.rb', line 16

def self.generate(args)
  unless args.length == 2
    puts <<-TEXT
Error: Not enough arguments for command 'generate'

Usage: gutsy generate [config_path] [output_path]

DESCRIPTION
Generates a gem scaffold and resource API clients on top of a heroics-generated client.

ARGUMENTS
[config_path] - Path to gutsy configuration file
[output_path] - Path to output generated API client gem(s).
                (Will be created if it doesn't exist)
TEXT
    exit 1
  end

  config_path = File.expand_path(args[0])
  output_path = File.expand_path(args[1])

  config = Gutsy::Configuration.load_from_file!(config_path)

  config.apps.each do |app_config|
    generator = Gutsy::Cli::Generator.new(app_config, output_path)
    begin
      generator.generate!
    rescue => e
      puts "FAIL"
      puts e.message
      puts e.backtrace.join("\n")
      exit 1
    end
  end

  exit 0
end

.helpObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gutsy/cli.rb', line 59

def self.help
  puts <<-TEXT
Usage: gutsy [command] [options]

DESCRIPTION
Generates gem wrappers around heroics-generated API clients
built with JSON Schema. (Enough layers of generation for ya?)

COMMANDS
generate      scaffolds out an API client
version       returns the gutsy version
help          displays this message

Shouts out Mr. Gutsy. Keep on plugging in the Wasteland.
  TEXT
  exit 0
end

.parse!(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/gutsy/cli.rb', line 3

def self.parse!(args)
  command = args[0]

  case command
  when "generate"
    generate(args[1..-1])
  when "version"
    version
  else
    help
  end
end

.versionObject



54
55
56
57
# File 'lib/gutsy/cli.rb', line 54

def self.version
  puts "Gutsy version #{Gutsy::VERSION}"
  exit 0
end