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

#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #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



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

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

#app_nameObject



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

def app_name
  File.basename(app_full_path)
end

#app_rootObject



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

def app_root
  File.dirname(app_full_path)
end

#cookbook_nameObject



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

def cookbook_name
  app_name
end

#cookbook_rootObject



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

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

#params_valid?Boolean

Returns:

  • (Boolean)


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

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



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

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



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

def recipe
  "app"
end

#runObject



43
44
45
46
47
48
49
50
51
52
# 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
end

#setup_contextObject



54
55
56
57
58
59
60
# File 'lib/chef-dk/command/generator_commands/app.rb', line 54

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)
end