Sha256: fd373bfa2a0e90dbd3ed1b826b254f9f08e91f34431888d893daf793715f6d18
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require "chef/fork/commands" require "chef/role" require "json" class Chef class Fork module Commands class Role < Noop def run(args=[]) rest = optparse.order(args) case rest.first when "edit" role_edit(rest.slice(1..-1) || []) when "from" role_from(rest.slice(1..-1) || []) when "list" role_list(rest.slice(1..-1) || []) when "show" role_show(rest.slice(1..-1) || []) when "upload" role_upload(rest.slice(1..-1) || []) else raise(NameError.new(rest.inspect)) end end private def role_edit(args=[]) raise(NotImplementedError.new(args.inspect)) end def role_from(args=[]) case args.shift when "file" rome_from_file(args.slice(1..-1)) else raise(NameError.new(args.inspect)) end end def role_from_file(args=[]) role_upload(args) end def role_list(args=[]) raise(NotImplementedError.new(args.inspect)) end def role_show(args=[]) args.each do |role_name| role = Chef::Role.load(role_name) STDOUT.puts(JSON.pretty_generate(role_to_hash(role.to_hash()))) end end def role_upload(args=[]) role_paths = [ Chef::Config[:role_path] ].flatten args.each do |role_name| candidates = role_paths.map { |path| File.join(path, "#{role_name}.rb") } if file = candidates.select { |candidate| File.exist?(candidate) }.first role = Chef::Role.from_disk(role_name) p(role) # TODO: do upload end end raise(NotImplementedError.new(args.inspect)) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
chef-fork-0.1.2 | lib/chef/fork/commands/role.rb |