require "devops-client/options/common_options"

class ImageOptions < CommonOptions

  commands :create, :delete, :list, :show, :update

  COMMAND_NAME = "image"

  def initialize args, def_options
    super(args, def_options)
    self.header = I18n.t("headers.image")
    self.list_params = ["[PROVIDER]"]
    self.show_params = ["IMAGE"]
    self.create_params = []
    self.delete_params = ["IMAGE" ]
    self.update_params = ["IMAGE", "FILE"]
  end

  def create_options
    self.options do |parser, options|
      parser.banner << self.create_banner
      parser.resource_name = :image

      parser.recognize_option_value(:provider)
      parser.recognize_option_value(:provider_account)
      parser.recognize_option_value(:image_id)
      parser.recognize_option_value(:ssh_username)
    end
  end

  def list_options
    self.options do |parser, options|
      parser.banner << self.list_banner

      parser.recognize_option_value(:provider_account, resource_name: :image)
    end
  end

  extend_options_method :list_options do |options|
    if args[2] == "provider" and args[3]
      options[:given_provider] = args[3]
    elsif args[2]
      options[:given_provider] = args[2]
    end
  end

end
