Sha256: 22359c61d9cae1e4c5f3e0b52bce9787946ac25751e2f6fe6ca9e673ab3a2ec3

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "thor"

require_relative "../session"
require_relative "./constants"

module NeetoDeploy
  class CLI
    module Addon
      class Info < CLI::Base
        include Constants
        include Session

        attr_reader :addon_name

        def initialize(options)
          super()
          @addon_name = options[:addon_name]
        end

        def run
          ui.execute_with_loading("Fetching info...") do
            send_request
          end
          print_output
        end

        private

          def flatten_hash_from(hash)
            hash.each_with_object({}) do |(key, value), memo|
              next flatten_hash_from(value).each do |k, v|
                memo["#{k}".intern] = v
              end if value.is_a? Hash
              memo[key] = value
            end
          end

          def send_request
            @response = send_get_request(addon_url(addon_name), {})
          end

          def print_output
            ui.error(@response["error"]) and return unless @response.success?

            flatten_hash_from(JSON[@response.body]).each do |k, v|
              ui.info("#{k}: #{v}")
            end
          end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
neetodeploy-1.1.10 lib/neeto_deploy/cli/addon/info.rb
neetodeploy-1.1.9 lib/neeto_deploy/cli/addon/info.rb
neetodeploy-1.1.8 lib/neeto_deploy/cli/addon/info.rb
neetodeploy-1.1.7 lib/neeto_deploy/cli/addon/info.rb
neetodeploy-1.1.6 lib/neeto_deploy/cli/addon/info.rb