Class: OsCtl::Repo::Cli::Command

Inherits:
Lib::Cli::Command
  • Object
show all
Defined in:
lib/osctl/repo/cli/command.rb

Direct Known Subclasses

Repo

Class Method Summary collapse

Class Method Details

.run(klass, method) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/osctl/repo/cli/command.rb', line 3

def self.run(klass, method)
  proc do |global_opts, opts, args|
    cmd = klass.new(global_opts, opts, args)

    begin
      cmd.method(method).call
    rescue OsCtl::Repo::ImageNotFound => e
      raise GLI::CustomExit.new(
        "Image not found: #{e.message}",
        OsCtl::Repo::EXIT_IMAGE_NOT_FOUND
      )
    rescue OsCtl::Repo::FormatNotFound => e
      raise GLI::CustomExit.new(
        "Format not found: #{e.message}",
        OsCtl::Repo::EXIT_FORMAT_NOT_FOUND
      )
    rescue OsCtl::Repo::BadHttpResponse => e
      raise GLI::CustomExit.new(
        "Unexpected HTTP error: #{e.message}",
        OsCtl::Repo::EXIT_HTTP_ERROR
      )
    rescue OsCtl::Repo::NetworkError => e
      raise GLI::CustomExit.new(
        "Unexpected network error: #{e.message}",
        OsCtl::Repo::EXIT_NETWORK_ERROR
      )
    end
  end
end