Skip to content

Instantly share code, notes, and snippets.

@zuazo
Created July 27, 2015 18:19
Show Gist options
  • Save zuazo/05a391ac71881d584b5a to your computer and use it in GitHub Desktop.
Save zuazo/05a391ac71881d584b5a to your computer and use it in GitHub Desktop.
Get Chef cookbook name from cookbook directory
#!/usr/bin/env ruby
#
# Syntax:
# $ cookbook_name_from_directory.rb [DIRECTORY]
#
require 'stringio'
require 'chef/cookbook/metadata'
Dir.chdir ARGV.first unless ARGV.empty?
metadata = Chef::Cookbook::Metadata.new
if File.exist?('metadata.rb')
metadata.from_file('metadata.rb')
elsif File.exist?('metadata.json')
metadata.from_json(IO.read('metadata.json'))
else
fail 'Cookbook metadata not found.'
end
puts metadata.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment