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, #configure_chef, #create_object, #delete_object, deps, #format_rest_error, guess_category, #highlight_config_error, #humanize_exception, #humanize_http_exception, inherited, #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

.common_optionsObject



28
29
30
31
32
33
# File 'lib/chef/chef_fs/knife.rb', line 28

def self.common_options
  option :repo_mode,
    :long => '--repo-mode MODE',
    :default => "default",
    :description => "Specifies the local repository layout.  Values: default or full"
end

Instance Method Details

#base_pathObject



35
36
37
38
39
40
# File 'lib/chef/chef_fs/knife.rb', line 35

def base_path
  @base_path ||= begin
    relative_to_base = Chef::ChefFS::PathUtils::relative_to(File.expand_path(Dir.pwd), chef_repo)
    relative_to_base == '.' ? '/' : "/#{relative_to_base}"
  end
end

#chef_fsObject



42
43
44
# File 'lib/chef/chef_fs/knife.rb', line 42

def chef_fs
  @chef_fs ||= Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", Chef::Config, config[:repo_mode])
end

#chef_repoObject



46
47
48
# File 'lib/chef/chef_fs/knife.rb', line 46

def chef_repo
  @chef_repo ||= File.expand_path(File.join(Chef::Config.cookbook_path, ".."))
end

#format_path(path) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/chef_fs/knife.rb', line 50

def format_path(path)
  if path[0,base_path.length] == base_path
    if path == base_path
      return "."
    elsif path[base_path.length] == "/"
      return path[base_path.length + 1, path.length - base_path.length - 1]
    elsif base_path == "/" && path[0] == "/"
      return path[1, path.length - 1]
    end
  end
  path
end

#local_fsObject



63
64
65
# File 'lib/chef/chef_fs/knife.rb', line 63

def local_fs
  @local_fs ||= Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir.new(chef_repo)
end

#pattern_argsObject



67
68
69
# File 'lib/chef/chef_fs/knife.rb', line 67

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

#pattern_args_from(args) ⇒ Object



71
72
73
# File 'lib/chef/chef_fs/knife.rb', line 71

def pattern_args_from(args)
  args.map { |arg| Chef::ChefFS::FilePattern::relative_to(base_path, arg) }.to_a
end