Sha256: f391688621bcec7a361e734bce791d0a40882e17bfe160d0a11902c9c8746e52

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Percheron
  module Commands
    class Abstract < Clamp::Command

      option([ '-c', '--config_file' ], 'CONFIG', 'Config file',
             default: Config::DEFAULT_CONFIG_FILE)

      option('--version', :flag, 'show version') do
        puts Percheron::VERSION
        exit(0)
      end

      def self.default_parameters!
        parameter('STACK_NAME', 'stack name', required: true)
        parameter('UNIT_NAMES', 'unit names', default: [], required: false) do |names|
          names.split(/,/)
        end
      end

      def self.default_create_parameters!
        default_parameters!
        option('--start', :flag, 'Start unit', default: false)
      end

      def default_config_file
        ENV.fetch('PERCHERON_CONFIG', Config::DEFAULT_CONFIG_FILE)
      end

      def execute
        stack.valid?
      rescue => e
        puts "%s\n%s\n" % [ e.inspect, e.backtrace ]
        signal_usage_error(e.message)
      end

      def stack
        return NullStack.new if stack_name.nil?
        Percheron::Stack.new(config, stack_name)
      end

      def config
        @config ||= begin
          Percheron::Config.new(config_file).tap do |c|
            Percheron::Connection.load!(c)
          end
        end
      rescue Errors::ConfigFileInvalid => e
        $logger.error e.inspect
        exit(1)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
percheron-0.7.7 lib/percheron/commands/abstract.rb