class ChefCLI::Command::GeneratorCommands::Repo
Generates a full “chef-repo” directory structure.
chef generate repo path/to/basename –generator-cookbook=path/to/generator –policy-only
## Repo
def initialize(params)
def initialize(params) @params_valid = true @repo_name = nil @use_policy = true @verbose = false super end
def params_valid?
def params_valid? @params_valid end
def read_and_validate_params
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
def recipe
def recipe "repo" end
def repo_full_path
def repo_full_path File.expand_path(repo_name_or_path, Dir.pwd) end
def repo_name
def repo_name File.basename(repo_full_path) end
def repo_root
def repo_root File.dirname(repo_full_path) end
def run
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
def setup_context
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
def use_policy?
def use_policy? @use_policy end
def verbose?
def verbose? @verbose end