class ChefDK::Command::GeneratorCommands::Repo

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

Generates a full “chef-repo” directory structure.

Attributes

errors[R]
repo_name_or_path[R]

Public Class Methods

new(params) click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 64
def initialize(params)
  @params_valid = true
  @repo_name = nil
  @use_policy = true
  @verbose = false
  super
end

Public Instance Methods

params_valid?() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 134
def params_valid?
  @params_valid
end
read_and_validate_params() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 119
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[:roles]
    @use_policy = false
  end
end
recipe() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 95
def recipe
  "repo"
end
repo_full_path() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 107
def repo_full_path
  File.expand_path(repo_name_or_path, Dir.pwd)
end
repo_name() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 99
def repo_name
  File.basename(repo_full_path)
end
repo_root() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 103
def repo_root
  File.dirname(repo_full_path)
end
run() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 72
def run
  read_and_validate_params
  if params_valid?
    setup_context
    msg("Generating Chef Infra repo #{repo_name}")
    chef_runner.converge
    msg("")
    msg("Your new Chef Infra repo is ready! Type `cd #{repo_name}` to enter it.")
    0
  else
    err(opt_parser)
    1
  end
end
setup_context() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 87
def setup_context
  super
  Generator.add_attr_to_context(:verbose, verbose?)
  Generator.add_attr_to_context(:repo_root, repo_root)
  Generator.add_attr_to_context(:repo_name, repo_name)
  Generator.add_attr_to_context(:use_policy, use_policy?)
end
use_policy?() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 111
def use_policy?
  @use_policy
end
verbose?() click to toggle source
# File lib/chef-dk/command/generator_commands/repo.rb, line 115
def verbose?
  @verbose
end