Sha256: ee2b02488a5ecef2c9bfaa79136a695522844a5ce264020605bfb2ee87044f66

Contents?: true

Size: 946 Bytes

Versions: 4

Compression:

Stored size: 946 Bytes

Contents

module Brightbox
  command [:servers] do |cmd|

    cmd.default_command :list

    cmd.desc "List servers"
    cmd.arg_name "[server-id...]"
    cmd.command [:list] do |c|

      c.desc "Group identifier"
      c.flag [:g, :group]

      c.action do |global_options, options, args|
        # Check this here before we make any network connections
        raise "A valid server group identifier is required for the group argument" unless options[:g].nil? || options[:g] =~ /^grp-.{5}$/

          if args.empty?
            servers = Server.find(:all)
        else
          servers = Server.find_or_call(args) do |id|
            warn "Couldn't find server #{id}"
          end
        end

        # Scope by group if a group identifier is specified
        servers = servers.select {|server| server.server_groups.any? {|grp| grp["id"] == options[:g] } } if options[:g]

        render_table(servers, global_options)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brightbox-cli-1.1.0 lib/brightbox-cli/commands/servers-list.rb
brightbox-cli-1.0.0 lib/brightbox-cli/commands/servers-list.rb
brightbox-cli-1.0.0.rc2 lib/brightbox-cli/commands/servers-list.rb
brightbox-cli-1.0.0.rc1 lib/brightbox-cli/commands/servers-list.rb