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

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command

Constructor Details

#initialize(params) ⇒ Repo

Returns a new instance of Repo.



43
44
45
46
47
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 43

def initialize(params)
  @params_valid = true
  @repo_name = nil
  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)


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

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



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

def read_and_validate_params
  arguments = parse_options(params)
  @repo_name_or_path = arguments[0]
  @params_valid = false unless @repo_name_or_path
end

#recipeObject



66
67
68
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 66

def recipe
  "repo"
end

#repo_full_pathObject



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

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

#repo_nameObject



70
71
72
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 70

def repo_name
  File.basename(repo_full_path)
end

#repo_rootObject



74
75
76
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 74

def repo_root
  File.dirname(repo_full_path)
end

#runObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 49

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
  else
    msg(banner)
    1
  end
end

#setup_contextObject



60
61
62
63
64
# File 'lib/chef-dk/command/generator_commands/repo.rb', line 60

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