require "devops-client/handler/handler" require "devops-client/handler/provider" require "devops-client/options/stack_template_options" require "devops-client/output/stack_template" # require 'devops-client/helpers/select_available' class StackTemplate < Handler output_with Output::StackTemplate def initialize(host, def_options={}) @host, @options = host, def_options @options_parser = StackTemplateOptions.new(ARGV, def_options) end def handle current_command = ARGV[1].to_sym @options, @args = @options_parser.parse_options_for!(current_command) case current_command when :list list_handler output when :show show_handler output when :create create_handler when :delete delete_handler end end def create_handler q = {} q[:provider] = options[:provider] || resources_selector.select_available_provider q[:id] = options[:id] || enter_parameter(I18n.t('handler.stack_template.create.id')) filepath = options[:template_file] || enter_parameter(I18n.t('handler.stack_template.create.template_file')) q[:template_body] = get_file_contents(filepath) json = JSON.pretty_generate(q) post_body("/stack_template/#{q[:provider]}", json) if question(I18n.t('handler.stack_template.question.create')){puts json} end def list_handler(provider=nil) provider ||= @options[:given_provider] @list = get_stack_templates(provider) end def get_stack_templates(provider=nil) if provider provider_stack_templates(provider) else get("/stack_templates") end end def show_handler r = inspect_parameters @options_parser.show_params, @args[2] unless r.nil? @options_parser.invalid_show_command abort(r) end @show = get "/stack_template/#{@args[2]}" end def delete_handler r = inspect_parameters(@options_parser.delete_params, @args[2]) unless r.nil? @options_parser.invalid_delete_command abort(r) end if question(I18n.t("handler.stack_template.question.delete", name: @args[2])) delete "/stack_template/#{@args[2]}" end end def provider_stack_templates(provider) if Providers.has_functionality?(provider, :stack_templates) @provider = true @list = get("/stack_templates/provider/#{provider}") else @options_parser.invalid_list_command abort() end end end