exe/dockerun in dockerun-0.3.6 vs exe/dockerun in dockerun-0.4.0

- old
+ new

@@ -1,121 +1,14 @@ #!/usr/bin/env ruby -#require 'bundler/setup' -require 'toolrack' -include TR::CondUtils - -require 'tty/prompt' require_relative '../lib/dockerun' -if ARGV.length == 0 - puts "dockerun version #{Dockerun::VERSION}" - puts Dockerun::Command::Dockerun.new.help +# Operations +# 1. [i]nit - Copy sample spec into project dir +# 2. [r]un - Run the spec (default without params) +# 3. [d]elete [c]ontainer - Delete container (using image name inside spec) +# 4. [d]elete [i]mage - Delete image (Using container name inside spec) +# 5. reset - Delete container and image -else - pmt = TTY::Prompt.new - - cmd = Dockerun::Command::Dockerun.new - res = cmd.parse(ARGV).params.to_h - case res[:command].downcase - when "init" - initCmd = Dockerun::Command::Init.new - argv = ARGV[1..-1] - begin - res2 = initCmd.parse(argv).run do |ops, val| - case ops - when :multiple_templates_detected - pmt.select("There are multiple templates available. Please select one of the template : ") do |m| - val.each do |v| - m.choice v, v - end - end - - when :prompt_user_configurables - pmt.say "\n The following are the configurable items for the template '#{val[:template]}' : \n", color: :yellow - res = { } - val[:userFields].each do |k,v| - res[k] = pmt.ask("#{k.to_s.capitalize} : ") do |s| - s.required v[:required] if not_empty?(v[:required]) and is_bool?(v[:required]) - s.value v[:default].to_s if not_empty?(v[:default]) - end - end - res - end - end - - STDOUT.puts "\nDockerfile written to '#{res2}'\n\n" - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - when "run", "r" - - begin - runCmd = Dockerun::Command::Run.new - argv = ARGV[1..-1] - runCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - - when "run-new-container", "rnc" - - begin - runCmd = Dockerun::Command::RunNewContainer.new - argv = ARGV[1..-1] - runCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - - when "run-new-image", "rni" - - begin - runCmd = Dockerun::Command::RunNewImage.new - argv = ARGV[1..-1] - runCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - when "stop", "s" - - begin - runCmd = Dockerun::Command::StopContainer.new - argv = ARGV[1..-1] - runCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - end - - - - - when "rmi", "remove-image" - begin - riCmd = Dockerun::Command::ResetImage.new - argv = ARGV[1..-1] - riCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - - when "remove-container","rmc" - # remove container - begin - riCmd = Dockerun::Command::RemoveContainer.new - argv = ARGV[1..-1] - riCmd.parse(argv).run - rescue TTY::Reader::InputInterrupt - pmt.say "\n\n Aborted\n", color: :yellow - end - - - else - STDERR.puts "Unknown command '#{res[:command]}'" - STDOUT.puts cmd.help - end -end +cli = Dockerun::CliEngine.new +cli.parse_argv(ARGV)