Class: Chef::ChefFS::Knife
- Inherits:
-
Knife
- Object
- Knife
- Chef::ChefFS::Knife
show all
- Defined in:
- lib/chef/chef_fs/knife.rb
Constant Summary
Constants inherited
from Knife
Knife::CHEF_ORGANIZATION_MANAGEMENT, Knife::KNIFE_ROOT, Knife::OFFICIAL_PLUGINS, Knife::OPSCODE_HOSTED_CHEF_ACCESS_CONTROL, Knife::VERSION
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, chef_config_dir, common_name, #config_file_defaults, #config_file_settings, config_loader, #config_source, #create_object, #delete_object, dependency_loaders, #format_rest_error, guess_category, #humanize_exception, #humanize_http_exception, #initialize, list_commands, load_commands, load_config, load_deps, #maybe_setup_fips, #merge_configs, msg, #noauth_rest, #parse_options, reset_config_loader!, reset_subcommands!, #rest, #root_rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_files, subcommand_loader, subcommands, subcommands_by_category, #test_mandatory_field, ui, unnamed?, use_separate_defaults?, #username
Constructor Details
This class inherits a constructor from Chef::Knife
Class Method Details
.deps ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/chef/chef_fs/knife.rb', line 30
def self.deps
super do
require "chef/config" unless defined?(Chef::Config)
require "chef/chef_fs/config" unless defined?(Chef::ChefFS::Config)
require "chef/chef_fs/file_pattern" unless defined?(Chef::ChefFS::FilePattern)
require "chef/chef_fs/path_utils" unless defined?(Chef::ChefFS::PathUtils)
yield
end
end
|
.inherited(c) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/chef/chef_fs/knife.rb', line 40
def self.inherited(c)
super
c.deps do
end
end
|
Instance Method Details
#chef_fs ⇒ Object
78
79
80
|
# File 'lib/chef/chef_fs/knife.rb', line 78
def chef_fs
@chef_fs_config.chef_fs
end
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/chef/chef_fs/knife.rb', line 60
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]
if config[:chef_repo_path]
Chef::Config[:chef_repo_path] = config[:chef_repo_path]
Chef::ChefFS::Config::INFLECTIONS.each_value 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, ui)
ChefUtils::DefaultThreadPool.instance.threads = (Chef::Config[:concurrency] || 10) - 1
end
|
#create_chef_fs ⇒ Object
82
83
84
|
# File 'lib/chef/chef_fs/knife.rb', line 82
def create_chef_fs
@chef_fs_config.create_chef_fs
end
|
#create_local_fs ⇒ Object
90
91
92
|
# File 'lib/chef/chef_fs/knife.rb', line 90
def create_local_fs
@chef_fs_config.create_local_fs
end
|
#discover_repo_dir(dir) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/chef/chef_fs/knife.rb', line 148
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
parent = File.dirname(dir)
if parent && parent != dir
discover_repo_dir(parent)
else
nil
end
end
|
140
141
142
|
# File 'lib/chef/chef_fs/knife.rb', line 140
def format_path(entry)
@chef_fs_config.format_path(entry)
end
|
#local_fs ⇒ Object
86
87
88
|
# File 'lib/chef/chef_fs/knife.rb', line 86
def local_fs
@chef_fs_config.local_fs
end
|
#parallelize(inputs, options = {}, &block) ⇒ Object
144
145
146
|
# File 'lib/chef/chef_fs/knife.rb', line 144
def parallelize(inputs, options = {}, &block)
inputs.parallel_map(&block)
end
|
#pattern_arg_from(arg) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/chef/chef_fs/knife.rb', line 102
def pattern_arg_from(arg)
inferred_path = nil
if Chef::ChefFS::PathUtils.is_absolute?(arg)
if possible_server_path = @chef_fs_config.server_path(arg)
ui.warn("The absolute path provided is suspicious: #{arg}")
ui.warn("If you wish to refer to a file location, please provide a path that is rooted at the chef-repo.")
ui.warn("Consider writing '#{possible_server_path}' instead of '#{arg}'")
end
inferred_path = arg
elsif arg.start_with?("~")
ui.warn("A path relative to a user home directory has been provided: #{arg}")
ui.warn("Paths provided need to be rooted at the chef-repo being considered or be relative paths.")
inferred_path = @chef_fs_config.server_path(arg)
ui.warn("Using '#{inferred_path}' as the path instead of '#{arg}'.")
elsif Pathname.new(arg).absolute?
ui.warn("An absolute file system path that isn't a server path was provided: #{arg}")
ui.warn("Paths provided need to be rooted at the chef-repo being considered or be relative paths.")
inferred_path = @chef_fs_config.server_path(arg)
ui.warn("Using '#{inferred_path}' as the path instead of '#{arg}'.")
elsif @chef_fs_config.base_path.nil?
ui.error("Attempt to use relative path '#{arg}' when current directory is outside the repository path.")
ui.error("Current working directory is '#{@chef_fs_config.cwd}'.")
exit(1)
else
inferred_path = Chef::ChefFS::PathUtils.join(@chef_fs_config.base_path, arg)
end
Chef::ChefFS::FilePattern.new(inferred_path)
end
|
#pattern_args ⇒ Object
94
95
96
|
# File 'lib/chef/chef_fs/knife.rb', line 94
def pattern_args
@pattern_args ||= pattern_args_from(name_args)
end
|
#pattern_args_from(args) ⇒ Object
98
99
100
|
# File 'lib/chef/chef_fs/knife.rb', line 98
def pattern_args_from(args)
args.map { |arg| pattern_arg_from(arg) }
end
|