Class: HolePunch::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/holepunch/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



26
27
28
29
# File 'lib/holepunch/cli.rb', line 26

def initialize(*args)
  super
  Logger.output = LoggerOutputStdio.new
end

Instance Method Details

#applyObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/holepunch/cli.rb', line 46

def apply
  Logger.fatal("AWS Access Key ID not defined. Use --aws-access-key or AWS_ACCESS_KEY_ID") if options[:'aws-access-key'].nil?
  Logger.fatal("AWS Secret Access Key not defined. Use --aws-secret-access-key or AWS_SECRET_ACCESS_KEY") if options[:'aws-secret-access-key'].nil?
  Logger.fatal("AWS Region not defined. Use --aws-region or AWS_REGION") if options[:'aws-region'].nil?
  Logger.verbose = options[:verbose]

  definition = Definition.build(options[:file], options[:env])
  ec2 = EC2.new({
    access_key_id:     options[:'aws-access-key'],
    secret_access_key: options[:'aws-secret-access-key'],
    region:            options[:'aws-region'],
  })
  ec2.apply(definition)

rescue EnvNotDefinedError => e
  Logger.fatal('You have security groups that use an environment, but you did not specify one. See --help')
rescue HolePunchError => e
  Logger.fatal(e.message)
end

#service(name = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/holepunch/cli.rb', line 75

def service(name = nil)
  Logger.verbose = options[:verbose]

  definition = Definition.build(options[:file], options[:env])

  if options[:list]
    definition.services.keys.sort.each do |name|
      puts name
    end
  else
    service = definition.services[name]
    Logger.fatal("service '#{name}' not found") if service.nil?
    puts service.groups.sort.join(',')
  end

rescue EnvNotDefinedError => e
  Logger.fatal('You have security groups that use an environment, but you did not specify one. See --help')
rescue HolePunchError => e
  Logger.fatal(e.message)
end

#versionObject



97
98
99
# File 'lib/holepunch/cli.rb', line 97

def version
  puts VERSION
end