using berkshelf programmatically

160 Views Asked by At

i am managing my cookbooks with berkshelf. i would like to play a little bit with the cookbook dependency graph. for instance:

  • given a cookbook, get its dependencies (the same as the resolver does it)
  • given a cookbook, get depended cookbooks (same as berks contingent)

i tried

require 'berkshelf'
Berkshelf::Lockfile.new(file_path: './Berksfile.lock')

but it did not work.

how can berkshelf be invoked programmatically under ruby and achieve the above?

2

There are 2 best solutions below

2
rathourarv On BEST ANSWER

If you have Berksfile, It might be helpful for you.


require 'berkshelf'

# initializing berksfile
s = Berkshelf::Berksfile.from_file('./find_versions/Berksfile')

#install dependencies to create Berksfile.lock 
s.install()

# parse lockfile
s.lockfile().parse()

# find dependencies
puts s.find('cookbook_name').locked_version

2
coderanger On

This is not supported, or anything even in the same area code as supported. We have no public Ruby APIs for this data, sorry. You can look at the Solve gem, but it's not really used outside of our own use cases.