class ChefCLI::Command::GeneratorCommands::CookbookCodeFile

cookbooks.
A base class for generators that add individual files to existing
## CookbookCodeFile

def cookbook_name

def cookbook_name
  File.basename(cookbook_path)
end

def cookbook_root

def cookbook_root
  File.dirname(cookbook_path)
end

def initialize(params)

def initialize(params)
  @params_valid = true
  @cookbook_full_path = nil
  @new_file_basename = nil
  @errors = []
  @params = params
  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)
  case arguments.size
  when 1
    @new_file_basename = arguments[0]
    @cookbook_path = Dir.pwd
    validate_cookbook_path
  when 2
    @cookbook_path = arguments[0]
    @new_file_basename = arguments[1]
  else
    @params_valid = false
  end
end

def run

def run
  read_and_validate_params
  if params_valid?
    setup_context
    chef_runner.converge
  else
    errors.each { |error| err("Error: #{error}") }
    parse_options(params)
    msg(opt_parser)
    1
  end
end

def setup_context

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

def validate_cookbook_path

def validate_cookbook_path
  unless File.file?(File.join(cookbook_path, "metadata.rb"))
    @errors << "Directory #{cookbook_path} is not a cookbook"
    @params_valid = false
  end
end