class Bakist::CLI

Attributes

bakist_config[W]

Public Instance Methods

bakist_config() click to toggle source
# File lib/bakist/cli.rb, line 83
def bakist_config
  @bakist_config ||= if options[:remote]
    Bakist::RemoteConfig.from_file(config_path, remote)
  else
    Bakist::Config.from_file(config_path)
  end.tap do |config|
    config.merge!(user_config) if user_config_path
    config.merge!(shop_config) if shop_config_path
    #config.merge!(shop_managed_user_config) if shop_managed_user_config_path
  end
end
chef() click to toggle source
# File lib/bakist/cli.rb, line 30
def chef
  #begin
    say 'Bakist is Fetching Cookbooks', :green, true, false
    install_cookbooks if cheffile_exists?        
    say 'Bakist is Preparing to Bake', :green, true, false
    bakist_config.run_chef
  #rescue Exception => msg
  #  say msg.backtrace.inspect
  #  say ' Your Bakery files were not found. Please make sure ', :RED, false
  #  say '~/.bakery/', :YELLOW, false, false
  #  say ' exists', :RED, true, false
  #  say '', nil, nil, false
  #end
end
config() click to toggle source
# File lib/bakist/cli.rb, line 54
def config
  Kernel.ap(bakist_config.as_node_json)
end
install_cookbooks() click to toggle source
# File lib/bakist/cli.rb, line 59
def install_cookbooks

  Dir.chdir(File.dirname(config_path)) do
    Librarian::Chef::Cli.with_environment do
      Librarian::Chef::Cli.new.install
    end
  end

  if user_config_path
    say 'Bakist is Fetching User-Specific Cookbooks', :green, true, false
    begin
      Dir.chdir(File.dirname(user_config_path)) do
        Librarian::Chef::Cli.with_environment do
          libchef = Librarian::Chef::Cli.new.install
        end
      end
    rescue
      say 'Error getting user-specific cookbooks, scratching.', :red
      abort
    end
  end

end
run_recipe(*recipes) click to toggle source
# File lib/bakist/cli.rb, line 48
def run_recipe(*recipes)
  bakist_config.royal_crown.recipes = recipes
  chef
end

Private Instance Methods

cheffile_exists?() click to toggle source
# File lib/bakist/cli.rb, line 117
def cheffile_exists?
  File.exists?(File.expand_path("~/.bakery/Cheffile"))
end
config_path() click to toggle source
# File lib/bakist/cli.rb, line 121
def config_path
  @config_path ||= File.expand_path("~/.bakery/bakeryrc")
end
remote() click to toggle source
# File lib/bakist/cli.rb, line 109
def remote
  @remote ||= if options[:identity]
    Bakist::Remote.from_uri(options[:remote], options[:identity])
  else
    Bakist::Remote.from_uri(options[:remote])
  end
end
shop_config() click to toggle source
# File lib/bakist/cli.rb, line 97
def shop_config
  Bakist::Config.from_file(shop_config_path)
end
shop_config_path() click to toggle source
# File lib/bakist/cli.rb, line 141
def shop_config_path
  shop_config_path = File.expand_path("~/.bakery/shoprc")
  if File.exists?(shop_config_path)
    @shop_config_path ||= shop_config_path
  end
end
shop_managed_user_config() click to toggle source
# File lib/bakist/cli.rb, line 105
def shop_managed_user_config
  Bakist::Config.from_file(shop_managed_user_config_path)
end
shop_managed_user_config_path() click to toggle source

TODO: Fix librarian cookbook path defaults

# File lib/bakist/cli.rb, line 126
def shop_managed_user_config_path
#  current_user = ENV['SUDO_USER'] ||= ENV['USER']
#  shop_managed_user_config_path = File.expand_path("~/.bakery/bakers/#{current_user}/bakeryrc")
#  if File.exists?(shop_managed_user_config_path)
#    @shop_managed_user_config_path ||= shop_managed_user_config_path
#  end
end
user_config() click to toggle source
# File lib/bakist/cli.rb, line 101
def user_config
  Bakist::Config.from_file(user_config_path)
end
user_config_path() click to toggle source
# File lib/bakist/cli.rb, line 134
def user_config_path
  user_config_path = File.expand_path("~/.bakist/bakistrc")
  if File.exists?(user_config_path)
    @user_config_path ||= user_config_path
  end
end