Sha256: 8f711ea6722b139d5ecf7cd92293f3452e197b4242e02ab0c76b58b6605f3165

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 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\n%s\n\n" % [ e.inspect, e.backtrace.join("\n") ]
        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

4 entries across 4 versions & 1 rubygems

Version Path
percheron-0.7.11 lib/percheron/commands/abstract.rb
percheron-0.7.10 lib/percheron/commands/abstract.rb
percheron-0.7.9 lib/percheron/commands/abstract.rb
percheron-0.7.8 lib/percheron/commands/abstract.rb