Sha256: eab79c77586f6936963e99d1198a27fac30e01e453f85c4dffb80da70fbc0b54

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module Hieracles
  class Commands

    attr_reader :available

    def initialize(config)
      @config = config
      @formatter = Object.const_get("Hieracles::Formats::#{@config.format}")
      @available = %w(info files params paths modules allparams facts)
    end

    def run(command, arg, extra)
      if arg and arg[/\./] # poor way to detect if it is a fqdn
        if Hieracles::Registry.nodes(@config).include? arg
          puts call_node(command.to_sym, arg, extra)
        else
          puts "node '#{arg}' not found"
        end
      else
        if respond_to? command
          send command.to_sym, arg, extra
        else
          # not a node
          puts "'#{arg}' is not a FQDN."
        end
      end
    end

    def farms(arg, extra)
      if arg
        arg = [arg]
      else
        arg = []
      end
      formatter = @formatter.new nil
      farms = Hieracles::Registry.farms_nodes(@config, 'local', true)
      puts formatter.build_list(farms, nil, arg)
    end

    def modules(arg, extra)
      if arg
        arg = [arg]
      else
        arg = []
      end
      formatter = @formatter.new nil
      modules = Hieracles::Registry.nodes_modules(@config, 'local', arg)
      puts formatter.build_list(modules, nil, arg)
    end

    def call_node(command, fqdn, extra)
      node = Hieracles::Node.new fqdn, @config
      formatter = @formatter.new node
      formatter.send command, extra
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hieracles-0.4.2 lib/hieracles/commands.rb
hieracles-0.4.1 lib/hieracles/commands.rb
hieracles-0.4.0 lib/hieracles/commands.rb