Class: Chef::ChefFS::Knife

Inherits:
Knife show all
Defined in:
lib/chef/chef_fs/knife.rb

Instance Attribute Summary

Attributes inherited from Knife

#name_args, #ui

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Knife

#api_key, #apply_computed_config, category, common_name, #config_file_settings, #create_object, #delete_object, dependency_loaders, #format_rest_error, guess_category, #highlight_config_error, #humanize_exception, #humanize_http_exception, #initialize, list_commands, load_commands, load_deps, #locate_config_file, #merge_configs, msg, #noauth_rest, #parse_options, #read_config_file, reset_subcommands!, #rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_loader, subcommands, subcommands_by_category, ui, unnamed?, use_separate_defaults?, #username

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::PathSanity

#enforce_path_sanity

Constructor Details

This class inherits a constructor from Chef::Knife

Class Method Details

.depsObject

Workaround for CHEF-3932



25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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

  option :repo_mode,
    :long => '--repo-mode MODE',
    :description => "Specifies the local repository layout.  Values: static, everything, hosted_everything.  Default: everything/hosted_everything"

  option :chef_repo_path,
    :long => '--chef-repo-path PATH',
    :description => 'Overrides the location of chef repo. Default is specified by chef_repo_path in the config'

  option :concurrency,
    :long => '--concurrency THREADS',
    :description => 'Maximum number of simultaneous requests to send (default: 10)'
end

Instance Method Details

#chef_fsObject



73
74
75
# File 'lib/chef/chef_fs/knife.rb', line 73

def chef_fs
  @chef_fs_config.chef_fs
end

#configure_chefObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chef/chef_fs/knife.rb', line 55

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 overrides all other paths
  if config[:chef_repo_path]
    Chef::Config[:chef_repo_path] = config[:chef_repo_path]
    Chef::ChefFS::Config::PATH_VARIABLES.each do |variable_name|
      Chef::Config[variable_name.to_sym] = chef_repo_paths.map { |path| File.join(path, "#{variable_name[0..-6]}s") }
    end
  end

  @chef_fs_config = Chef::ChefFS::Config.new(Chef::Config)

  Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1
end

#create_chef_fsObject



77
78
79
# File 'lib/chef/chef_fs/knife.rb', line 77

def create_chef_fs
  @chef_fs_config.create_chef_fs
end

#create_local_fsObject



85
86
87
# File 'lib/chef/chef_fs/knife.rb', line 85

def create_local_fs
  @chef_fs_config.create_local_fs
end

#format_path(entry) ⇒ Object



107
108
109
# File 'lib/chef/chef_fs/knife.rb', line 107

def format_path(entry)
  @chef_fs_config.format_path(entry)
end

#local_fsObject



81
82
83
# File 'lib/chef/chef_fs/knife.rb', line 81

def local_fs
  @chef_fs_config.local_fs
end

#parallelize(inputs, options = {}, &block) ⇒ Object



111
112
113
# File 'lib/chef/chef_fs/knife.rb', line 111

def parallelize(inputs, options = {}, &block)
  Chef::ChefFS::Parallelizer.parallelize(inputs, options, &block)
end

#pattern_argsObject



89
90
91
# File 'lib/chef/chef_fs/knife.rb', line 89

def pattern_args
  @pattern_args ||= pattern_args_from(name_args)
end

#pattern_args_from(args) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/chef/chef_fs/knife.rb', line 93

def pattern_args_from(args)
  # TODO support absolute file paths and not just patterns?  Too much?
  # Could be super useful in a world with multiple repo paths
  args.map do |arg|
    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
      @chef_fs_config.require_chef_repo_path
      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
end