Class: Containers::CLI

Inherits:
Thor
  • Object
show all
Includes:
Commandable, Configurable
Defined in:
lib/containers/cli.rb,
lib/containers/commands/up.rb,
lib/containers/commands/bin.rb,
lib/containers/commands/bash.rb,
lib/containers/commands/down.rb,
lib/containers/commands/exec.rb,
lib/containers/commands/list.rb,
lib/containers/commands/stop.rb,
lib/containers/commands/tail.rb,
lib/containers/commands/start.rb,
lib/containers/commands/attach.rb,
lib/containers/commands/inspect.rb,
lib/containers/commands/restart.rb,
lib/containers/commands/ruby/rake.rb,
lib/containers/commands/yarn/yarn.rb,
lib/containers/commands/rails/rails.rb,
lib/containers/commands/ruby/bundle.rb,
lib/containers/commands/config/print.rb

Constant Summary

Constants included from Configurable

Containers::Configurable::DEFAULT_CONFIGURATION

Constants included from Commandable

Containers::Commandable::PREFIX

Instance Method Summary collapse

Methods included from Configurable

#app_directory, #app_name, #configuration, #docker_compose_files, #docker_default_service, #docker_directory, gitname, #organization_name

Methods included from Commandable

#execute_command, #puts_command

Instance Method Details

#attach(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/attach.rb', line 7

def attach(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "docker attach #{container} #{args.join " "}"
end

#bash(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/bash.rb', line 7

def bash(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers exec -c #{container} bash #{args.join " "}"
end

#bin(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/bin.rb', line 7

def bin(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers exec -c #{container} bin/#{args.join " "}"
end

#bundle(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/ruby/bundle.rb', line 7

def bundle(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers exec -c #{container} bundle #{args.join " "}"
end

#config_print(*args) ⇒ Object



5
6
7
# File 'lib/containers/commands/config/print.rb', line 5

def config_print(*args)
  awesome_print configuration
end

#down(*args) ⇒ Object



5
6
7
# File 'lib/containers/commands/down.rb', line 5

def down(*args)
  execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} down #{args.join " "}"
end

#exec(*args) ⇒ Object



8
9
10
11
# File 'lib/containers/commands/exec.rb', line 8

def exec(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "docker exec -it #{container} #{args.join " "}"
end

#inspect(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/inspect.rb', line 7

def inspect(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "docker inspect #{args.join " "} #{container}"
end

#list(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/containers/commands/list.rb', line 8

def list(*args)
  return execute_command "docker ps -a | grep #{app_name}" if options[:detailed]

  if options[:service]
    command = "containers list"
    puts_command "#{command} | #{Rainbow("(strip app_name)").green.faint}"
    list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(PREFIX) }
    puts list.map { |item| item.gsub(/\A#{app_name}-|\s/, "") }.sort.join("\n")
    return
  end

  command = "containers list -d"
  puts_command "#{command} | #{Rainbow("(strip docker details)").green.faint}"
  list = `#{command}`.split("\n").reject { |item| item.strip == "" || item.include?(PREFIX) }
  puts list.map { |item| item.split(" ").last.strip }.sort.join("\n")
end

#rails(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/rails/rails.rb', line 7

def rails(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers bundle -c #{container} exec rails #{args.join " "}"
end

#rake(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/ruby/rake.rb', line 7

def rake(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers exec -c #{container} rake #{args.join " "}"
end

#restart(*args) ⇒ Object



7
8
9
10
11
# File 'lib/containers/commands/restart.rb', line 7

def restart(*args)
  requested_container_names.each do |container_name|
    execute_command "docker restart #{args.join " "} #{container_name}", replace_current_process: false
  end
end

#start(*args) ⇒ Object



7
8
9
10
11
# File 'lib/containers/commands/start.rb', line 7

def start(*args)
  requested_container_names.each do |container_name|
    execute_command "docker start #{args.join " "} #{container_name}", replace_current_process: false
  end
end

#stop(*args) ⇒ Object



7
8
9
10
11
# File 'lib/containers/commands/stop.rb', line 7

def stop(*args)
  requested_container_names.each do |container_name|
    execute_command "docker stop #{args.join " "} #{container_name}", replace_current_process: false
  end
end

#tail(*args) ⇒ Object



8
9
10
11
# File 'lib/containers/commands/tail.rb', line 8

def tail(*args)
  args << "--since 5m" unless args.include?("--since")
  execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} logs #{args.join " "} -f #{requested_service_names.join " "}"
end

#up(*args) ⇒ Object



5
6
7
# File 'lib/containers/commands/up.rb', line 5

def up(*args)
  execute_command "docker compose #{docker_compose_files.map { |f| "-f #{f}" }.join " "} up -d #{args.join " "}"
end

#yarn(*args) ⇒ Object



7
8
9
10
# File 'lib/containers/commands/yarn/yarn.rb', line 7

def yarn(*args)
  container = options[:container] || container_name(options[:service])
  execute_command "containers exec -c #{container} yarn #{args.join " "}"
end