class Chef::ChefFS::Knife

Public Class Methods

deps() { || ... } click to toggle source

Workaround for CHEF-3932

Calls superclass method Chef::Knife.deps
# File lib/chef/chef_fs/knife.rb, line 25
def self.deps
  super do
    require 'chef/config'
    require 'chef/chef_fs/parallelizer'
    require 'chef/chef_fs/config'
    require 'chef/chef_fs/file_pattern'
    require 'chef/chef_fs/path_utils'
    yield
  end
end
inherited(c) click to toggle source
Calls superclass method Chef::Knife.inherited
# File lib/chef/chef_fs/knife.rb, line 36
def self.inherited(c)
  super

  # Ensure we always get to do our includes, whether subclass calls deps or not
  c.deps do
  end

  c.options.merge!(options)
end

Public Instance Methods

chef_fs() click to toggle source
# File lib/chef/chef_fs/knife.rb, line 76
def chef_fs
  @chef_fs_config.chef_fs
end
configure_chef() click to toggle source
Calls superclass method
# File lib/chef/chef_fs/knife.rb, line 58
def configure_chef
  super
  Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
  Chef::Config[:concurrency] = config[:concurrency].to_i if config[:concurrency]

  # --chef-repo-path forcibly overrides all other paths
  if config[:chef_repo_path]
    Chef::Config[:chef_repo_path] = config[:chef_repo_path]
    %w(acl client cookbook container data_bag environment group node role user).each do |variable_name|
      Chef::Config.delete("#{variable_name}_path".to_sym)
    end
  end

  @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config, Dir.pwd, config)

  Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1
end
create_chef_fs() click to toggle source
# File lib/chef/chef_fs/knife.rb, line 80
def create_chef_fs
  @chef_fs_config.create_chef_fs
end
create_local_fs() click to toggle source
# File lib/chef/chef_fs/knife.rb, line 88
def create_local_fs
  @chef_fs_config.create_local_fs
end
discover_repo_dir(dir) click to toggle source
# File lib/chef/chef_fs/knife.rb, line 119
def discover_repo_dir(dir)
  %w(.chef cookbooks data_bags environments roles).each do |subdir|
    return dir if File.directory?(File.join(dir, subdir))
  end
  # If this isn't it, check the parent
  parent = File.dirname(dir)
  if parent && parent != dir
    discover_repo_dir(parent)
  else
    nil
  end
end
format_path(entry) click to toggle source
# File lib/chef/chef_fs/knife.rb, line 111
def format_path(entry)
  @chef_fs_config.format_path(entry)
end
local_fs() click to toggle source
# File lib/chef/chef_fs/knife.rb, line 84
def local_fs
  @chef_fs_config.local_fs
end
parallelize(inputs, options = {}, &block) click to toggle source
# File lib/chef/chef_fs/knife.rb, line 115
def parallelize(inputs, options = {}, &block)
  Chef::ChefFS::Parallelizer.parallelize(inputs, options, &block)
end
pattern_arg_from(arg) click to toggle source
# File lib/chef/chef_fs/knife.rb, line 100
def pattern_arg_from(arg)
  # TODO support absolute file paths and not just patterns?  Too much?
  # Could be super useful in a world with multiple repo paths
  if !@chef_fs_config.base_path && !Chef::ChefFS::PathUtils.is_absolute?(arg)
    # Check if chef repo path is specified to give a better error message
    ui.error("Attempt to use relative path '#{arg}' when current directory is outside the repository path")
    exit(1)
  end
  Chef::ChefFS::FilePattern.relative_to(@chef_fs_config.base_path, arg)
end
pattern_args() click to toggle source
# File lib/chef/chef_fs/knife.rb, line 92
def pattern_args
  @pattern_args ||= pattern_args_from(name_args)
end
pattern_args_from(args) click to toggle source
# File lib/chef/chef_fs/knife.rb, line 96
def pattern_args_from(args)
  args.map { |arg| pattern_arg_from(arg) }
end