Sha256: 1e833bd9341700730dec1344c282d45ef9c866c468821a2d99f868fbd88ef02d

Contents?: true

Size: 1.43 KB

Versions: 6

Compression:

Stored size: 1.43 KB

Contents

require 'ey-core/cli/subcommand'

module Ey
  module Core
    module Cli
      class Servers < Subcommand
        title 'servers'
        summary 'List servers you have access to'

        option :account,
          short: 'c',
          long: 'account',
          description: 'Filter by account name or id',
          argument: 'account'

        option :environment,
          short: 'e',
          long: 'environment',
          description: 'Filter by environment.',
          argument: 'environment'

        option :role,
          short: 'r',
          long: 'role',
          description: 'Filter by server role.',
          argument: 'role'

        def handle
          puts TablePrint::Printer.new(
            servers,
            [
              { id: { width: 10 } },
              :role,
              :provisioned_id,
              { public_hostname: { width: 50 } },
              :name,
            ]
          ).table_print
        end

        private
        def servers
          filter_opts = {}

          operator =
            if option(:environment)
              core_account.environments.first(name: option(:environment))
            else
              filter_opts[:account] = core_account.id if option(:account)
              core_client
            end

          filter_opts[:role] = option(:role).split(',') if option(:role)
          operator ? operator.servers.all(filter_opts) : nil
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ey-core-3.6.4 lib/ey-core/cli/servers.rb
ey-core-3.6.3 lib/ey-core/cli/servers.rb
ey-core-3.6.1 lib/ey-core/cli/servers.rb
groove-ey-core-3.6.3 lib/ey-core/cli/servers.rb
groove-ey-core-3.6.2 lib/ey-core/cli/servers.rb
groove-ey-core-3.6.1 lib/ey-core/cli/servers.rb