Sha256: 943e8b2454fae741b9bd69e1e200af6b35799383adae66187bab79761bf87280

Contents?: true

Size: 799 Bytes

Versions: 5

Compression:

Stored size: 799 Bytes

Contents

require 'guignol/commands/base'

Guignol::Shell.class_eval do
  desc 'list [PATTERNS]', 'List the status of all known instances'
  def list(*patterns)
    patterns.push('.*') if patterns.empty?
    Guignol::Commands::List.new(patterns).run
  end
end

module Guignol::Commands
  class List < Base
    private

    def run_on_server(instance, options = {})
      synchronize do
        shell.say instance.name.ljust(@max_width + 1)
        shell.say instance.state, colorize(instance.state)
      end
    end

    def before_run(configs)
      @max_width = configs.keys.map(&:size).max
    end

    def colorize(state)
      case state
        when 'running'            then :green
        when /starting|stopping/  then :yellow
        when 'nonexistent'        then :red
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guignol-0.3.4 lib/guignol/commands/list.rb
guignol-0.3.3 lib/guignol/commands/list.rb
guignol-0.3.2 lib/guignol/commands/list.rb
guignol-0.3.1 lib/guignol/commands/list.rb
guignol-0.3.0 lib/guignol/commands/list.rb