Class: ChefDK::Command::GeneratorCommands::Repo

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-dk/command/generator_commands/repo.rb

Overview

## Repo chef generate repo path/to/basename –generator-cookbook=path/to/generator –policy-only

Generates a full “chef-repo” directory structure.

Instance Attribute Summary collapse

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Base

#chef_runner, #generator_cookbook_name, #generator_cookbook_path, #have_git?

Methods included from ChefDK::Configurable

#chef_config, #chefdk_config, #config_loader, #generator_config, #knife_config

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initialize(params) ⇒ Repo

Returns a new instance of Repo.



56
57
58
59
60
61
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 56

def initialize(params)
  @params_valid = true
  @repo_name = nil
  @use_roles = true
  super
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



32
33
34
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 32

def errors
  @errors
end

#repo_name_or_pathObject (readonly)

Returns the value of attribute repo_name_or_path.



33
34
35
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 33

def repo_name_or_path
  @repo_name_or_path
end

Instance Method Details

#params_valid?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 117

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 102

def read_and_validate_params
  arguments = parse_options(params)
  @repo_name_or_path = arguments[0]
  unless @repo_name_or_path
    @params_valid = false
  end
  if !config[:roles].nil? && !config[:policy].nil?
    err("Roles and Policyfiles are exclusive. Please only select one.")
    @params_valid = false
  end
  if config[:policy]
    @use_roles = false
  end
end

#recipeObject



82
83
84
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 82

def recipe
  "repo"
end

#repo_full_pathObject



94
95
96
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 94

def repo_full_path
  File.expand_path(repo_name_or_path, Dir.pwd)
end

#repo_nameObject



86
87
88
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 86

def repo_name
  File.basename(repo_full_path)
end

#repo_rootObject



90
91
92
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 90

def repo_root
  File.dirname(repo_full_path)
end

#runObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 63

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
    0
  else
    err(opt_parser)
    1
  end
end

#setup_contextObject



75
76
77
78
79
80
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 75

def setup_context
  super
  Generator.add_attr_to_context(:repo_root, repo_root)
  Generator.add_attr_to_context(:repo_name, repo_name)
  Generator.add_attr_to_context(:use_roles, use_roles?)
end

#use_roles?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 98

def use_roles?
  @use_roles
end