module ContainerTasks

Public Instance Methods

del(keyword = nil) click to toggle source
# File lib/concerns/container_tasks.rb, line 34
def del(keyword = nil)
  ret = Container.find(keyword: keyword, name: options['name'], image: options['image'])
  Container.print_table(ret)
  say('The listed containers will be deleted, ARE YOU SURE.'.blue)
  answer = ask('(y=YES;q=QUIT;i=ASK one by one)', limited_to: %w[y q i])
  return if answer == 'q'
  ret.each do |container|
    if answer == 'i'
      say(container.to_s)
      each_answer = ask('going to delete? (y=YES,n=NO,q=QUIT):')
      next if each_answer == 'n'
      break if each_answer == 'q'
    end
    container.del
  end
end
exec(keyword = nil) click to toggle source
# File lib/concerns/container_tasks.rb, line 86
def exec(keyword = nil)
  ret = Container.find(keyword: keyword, name: options['name'], image: options['image'])
  if ret.count > 1
    Container.print_table(ret) { |item, index| "[#{index + 1}]#{item}" }
    question = ['please select one container to run:'].unshift(' ').unshift(' ').join("\n")
    say(question.blue)
    answer = ask('(q=QUIT;n=)', limited_to: ['q', *('1'..ret.count.to_s).to_a])
    return if answer == 'q'
  end

  command = options['cmd'] || ask_with_default('Any command you want to run?', 'echo hello')
  opts = options['opts'] || ask_with_default('Any option you want to set?', '-it')
  index = (answer ? answer.to_i : 1) - 1
  xcommand = ret[index].exec(opts, command)
  run(['dk', 'alias', options['alias'], xcommand].join(' ')) if options['alias']
  run(xcommand.join(' '))
end
lsc(keyword = nil) click to toggle source
# File lib/concerns/container_tasks.rb, line 18
def lsc(keyword = nil)
  ret = Container.find(keyword: keyword, name: options['name'], image: options['image'])
  Container.print_table(ret)
end