class ChefCLI::Policyfile::DSL
def validate_run_list_items(items, run_list_name = nil)
def validate_run_list_items(items, run_list_name = nil) items.each do |item| run_list_desc = run_list_name.nil? ? "Run List Item '#{item}'" : "Named Run List '#{run_list_name}' Item '#{item}'" item_name = Chef::RunList::RunListItem.new(item).name cookbook, separator, recipe = item_name.partition("::") if RUN_LIST_ITEM_COMPONENT.match(cookbook).nil? message = "#{run_list_desc} has invalid cookbook name '#{cookbook}'.\nCookbook names can only contain alphanumerics, hyphens, and underscores." # Special case when there's only one colon instead of two: if /[^:]:[^:]/.match?(cookbook) message << "\nDid you mean '#{item.sub(":", "::")}'?" end @errors << message end unless separator.empty? # we have a cookbook and recipe if RUN_LIST_ITEM_COMPONENT.match(recipe).nil? @errors << "#{run_list_desc} has invalid recipe name '#{recipe}'.\nRecipe names can only contain alphanumerics, hyphens, and underscores." end end end end