Class: ChefDK::Command::GeneratorCommands::App

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

Overview

## App chef generate app path/to/basename –generator-cookbook=path/to/generator

Generates a full “application” directory structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ App

Returns a new instance of App.



37
38
39
40
41
# File 'lib/chef-dk/command/generator_commands/app.rb', line 37

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

Instance Attribute Details

#app_name_or_pathObject (readonly)

Returns the value of attribute app_name_or_path.



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

def app_name_or_path
  @app_name_or_path
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#app_full_pathObject



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

def app_full_path
  File.expand_path(app_name_or_path, Dir.pwd)
end

#app_nameObject



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

def app_name
  File.basename(app_full_path)
end

#app_rootObject



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

def app_root
  File.dirname(app_full_path)
end

#cookbook_nameObject



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

def cookbook_name
  app_name
end

#cookbook_rootObject



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

def cookbook_root
  File.join(app_full_path, 'cookbooks')
end

#params_valid?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/chef-dk/command/generator_commands/app.rb', line 100

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



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

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

#recipeObject



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

def recipe
  "app"
end

#recipe_nameObject



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

def recipe_name
  "default"
end

#runObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef-dk/command/generator_commands/app.rb', line 43

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
  else
    msg(banner)
    1
  end
rescue ChefDK::ChefRunnerError => e
  err("ERROR: #{e}")
  1
end

#setup_contextObject



57
58
59
60
61
62
63
64
# File 'lib/chef-dk/command/generator_commands/app.rb', line 57

def setup_context
  super
  Generator.add_attr_to_context(:app_root, app_root)
  Generator.add_attr_to_context(:app_name, app_name)
  Generator.add_attr_to_context(:cookbook_root, cookbook_root)
  Generator.add_attr_to_context(:cookbook_name, cookbook_name)
  Generator.add_attr_to_context(:recipe_name, recipe_name)
end