lib/chef-cli/command/generator_commands/cookbook.rb in chef-cli-5.6.11 vs lib/chef-cli/command/generator_commands/cookbook.rb in chef-cli-5.6.12

- old
+ new

@@ -178,11 +178,15 @@ def cookbook_root File.dirname(cookbook_full_path) end def cookbook_full_path - File.expand_path(cookbook_name_or_path, Dir.pwd) + if !cookbook_name_or_path.nil? && !cookbook_name_or_path.empty? + File.expand_path(cookbook_name_or_path, Dir.pwd) + else + "" + end end def policy_mode? @policy_mode end @@ -201,9 +205,16 @@ if !@cookbook_name_or_path @params_valid = false elsif File.basename(@cookbook_name_or_path).include?("-") msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information.") + end + + if !generator_cookbook_path.empty? && + !cookbook_full_path.empty? && + File.identical?(Pathname.new(cookbook_full_path).parent, generator_cookbook_path) + err("The generator and the cookbook cannot be in the same directory. Please specify a cookbook directory that is different from the generator's parent.") + @params_valid = false end if config[:berks] && config[:policy] err("Berkshelf and Policyfiles are mutually exclusive. Please specify only one.") @params_valid = false