Sha256: 525a1a273ac90d56ca797105240e7a5294080c8a0d40db793c59caa280ded87d

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'toolrack'
require_relative 'run_keep'
require_relative 'run_del'
require_relative 'run'

module Docker
  module Cli
    class ArgsParser
      include TR::ArgUtils

      class ArgsParserException < StandardError; end

      OpsOption = [
        "run-keep", "rk",
        "run-del","rd",
        "run","r"
      ]

      arg_spec do 
        
        callback :pre_processing do |argv|
          select_runner(argv)
        end

      end

      def select_runner(argv)
        ops = argv.first
        if is_empty?(ops)
          raise ArgsParserException, "\n Operation is empty. First parameter is operation. Supported operations including : #{OpsOption.join(", ")}\n\n"
        else
          case ops
          when "run-keep", "rk" 
            Docker::Cli::Operations::RunKeep.new.parse_argv(argv[1..-1])

          when "run-del", "rd"
            Docker::Cli::Operations::RunDel.new.parse_argv(argv[1..-1])

          when "run", "r"
            Docker::Cli::Operations::Run.new.run

          else
            raise ArgsParserException, " Unknown operation '#{ops}'. First parameter is operation. Supported operations including : #{OpsOption.join(", ")}\n" 
          end
        end

        [true, argv[1..-1]]
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
docker-cli-0.5.4 lib/docker/cli/operations/args_parser.rb
docker-cli-0.5.3 lib/docker/cli/operations/args_parser.rb
docker-cli-0.5.2 lib/docker/cli/operations/args_parser.rb
docker-cli-0.5.1 lib/docker/cli/operations/args_parser.rb
docker-cli-0.5.0 lib/docker/cli/operations/args_parser.rb