Class: Kapten::CLI

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



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

def destroy

  config = Kapten::Helpers::validate_install
  return unless config

  unless Kapten::DockerApi::get_container( config['name'] )

    puts 'No environment to destroy!'
    puts 'Run "kapten start" to set it up'
    return

  end


  puts 'Destroying environment...'

  results = Kapten::DockerApi::destroy( config['name'] )

  puts 'Environment destroyed! Rebuild it by running "kapten start".'.green

end

#infoObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/kapten.rb', line 100

def info

  config = Kapten::Helpers::validate_install
  return unless config

  container = Kapten::DockerApi::get_container( config["name"] )

  if not container
    status = 'Not created'
  else
    status = "Not running".yellow
    status = "Running".green if container.json["State"]["Running"]
  end

  puts ''
  puts 'Name:    ' + config['name']
  puts 'Type:    ' + config['type']
  puts 'Status:  ' + status
  puts ''

end

#init(type) ⇒ Object



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
# File 'lib/kapten.rb', line 19

def init(type)

  if Kapten::Config.get
    puts 'Environment already initialized'
    puts 'Use "kapten start" to get developing'
    return
  end

  types = Kapten::Helpers::get_types

  if not types.include?(type)
    puts 'No such environment type'.red
    puts 'Available environment types are: ' + types.join(', ')
    return
  end

  name = options[:name] ||  File.basename(Dir.getwd)

  config = Kapten::Config::generate(type, name)

  Kapten::Config::save(config)

  puts 'Kapten initialized!'.green
  puts 'Use "kapten start" to load your environment'

end

#removeObject



124
125
126
127
128
129
130
131
132
133
# File 'lib/kapten.rb', line 124

def remove

  config = Kapten::Helpers::validate_install
  return unless config

  Kapten::Helpers::remove( config['name'] )

  puts 'All traces of Kapten have been removed'.green

end

#startObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/kapten.rb', line 48

def start

  config = Kapten::Helpers::validate_install
  return unless config

  image = Kapten::Helpers::get_image( config['type'] )

  Kapten::DockerApi::start( config['name'], image )

end

#stopObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kapten.rb', line 61

def stop

  config = Kapten::Helpers::validate_install
  return unless config

  puts 'Stopping Kapten environment...'

  results = Kapten::DockerApi::stop( config['name'] )

  puts 'Environment no longer active!'.green

end