Sha256: 8c728e3c3eb5e0e8270af2abdcb32cc8ffc866adeced865af89c42931ba451f7

Contents?: true

Size: 1.41 KB

Versions: 29

Compression:

Stored size: 1.41 KB

Contents

require 'belafonte'
require 'colorize'
require 'table_print'
require 'ey-core'
require 'ey-core/cli/helpers/core'

module Ey
  module Core
    module Cli
      class Subcommand < Belafonte::App
        include Ey::Core::Cli::Helpers::Core

        def setup
          $stdout = stdout
          $stderr = stderr
          $stdin = stdin
          $kernel = kernel
        end

        def run_handle
          super
        rescue Ey::Core::Response::Error => e
          if ENV["DEBUG"]
            puts e.inspect
            puts e.backtrace
          end
          handle_core_error(e)
        rescue => e
          if ENV["DEBUG"]
            puts e.inspect
            puts e.backtrace
          end
          stderr.puts "Error:".red
          stderr.puts Wrapomatic.wrap(e.message, indents: 1)
          raise SystemExit.new(255)
        end

        #TODO: a lot more errors that would could handle with nice messages, eventually this should probably be it's own class
        def handle_core_error(e)
          stderr.puts "Error: #{e.error_type}".red
          (e.response.body["errors"] || [e.message]).each do |message|
            stderr.puts Wrapomatic.wrap(message, indents: 1)
          end
          if e.is_a?(Ey::Core::Response::Unauthorized)
            stderr.puts "Check the contents of ~/.ey-core vs https://cloud.engineyard.com/cli"
          end
          raise SystemExit.new(255)
        end

      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
ey-core-3.6.4 lib/ey-core/cli/subcommand.rb
ey-core-3.6.3 lib/ey-core/cli/subcommand.rb
ey-core-3.6.1 lib/ey-core/cli/subcommand.rb
groove-ey-core-3.6.3 lib/ey-core/cli/subcommand.rb
groove-ey-core-3.6.2 lib/ey-core/cli/subcommand.rb
groove-ey-core-3.6.1 lib/ey-core/cli/subcommand.rb
ey-core-3.5.0 lib/ey-core/cli/subcommand.rb
ey-core-3.4.4 lib/ey-core/cli/subcommand.rb
ey-core-3.4.2 lib/ey-core/cli/subcommand.rb
ey-core-3.4.1 lib/ey-core/cli/subcommand.rb
ey-core-3.4.0 lib/ey-core/cli/subcommand.rb
ey-core-3.3.1 lib/ey-core/cli/subcommand.rb
ey-core-3.3.0 lib/ey-core/cli/subcommand.rb
ey-core-3.2.6 lib/ey-core/cli/subcommand.rb
ey-core-3.2.5 lib/ey-core/cli/subcommand.rb
ey-core-3.2.4 lib/ey-core/cli/subcommand.rb
ey-core-3.2.3 lib/ey-core/cli/subcommand.rb
ey-core-3.2.2 lib/ey-core/cli/subcommand.rb
ey-core-3.2.1 lib/ey-core/cli/subcommand.rb
ey-core-3.2.0 lib/ey-core/cli/subcommand.rb