Class: Canals::Cli::Environment

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/canals/cli/environment.rb

Instance Method Summary collapse

Instance Method Details

#create(name, hostname) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/canals/cli/environment.rb', line 15

def create(name, hostname)
  user, host = hostname.split("@")
  if host.nil?
    host = hostname
    user = nil
  end
  opts = {name: name, hostname: host}.merge(options)
  opts[:user] = user if !user.nil?
  env = Canals::Environment.new(opts)
  Canals.repository.add_environment(env)
end

#show(env = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/canals/cli/environment.rb', line 28

def show(env=nil)
  if Canals.environments.empty?
    say "No environments currently defined."
    return
  end
  require 'terminal-table'
  rows = Canals.environments.select{ |e| env.nil? || e.name == env}.map{ |e| [(e.is_default? ? "*" : ""), e.name, e.user, e.hostname, e.pem] }
  table = Terminal::Table.new :headings => ['', 'Name', 'User', 'Hostname', 'PEM'], :rows => rows
  say table
end