class Chef::Knife::ScrubAttributes

Constants

DEFAULT_QUERY

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/scrub_attributes.rb, line 45
def run
  unless prefix = name_args.first
    show_usage
    ui.fatal 'You must specify a prefix of attributes to scrub'
    exit 1
  end

  search = Chef::Search::Query.new
  search.search('node', config[:query]) do |node|
    extractor = Scrub::AttributeExtractor.create(node)

    unless extractor.has_key?(prefix)
      ui.msg format(node, "normal attribute #{prefix} not present")
      next
    end

    value = extractor.fetch(prefix)
    if config[:dry_run]
      ui.msg format(node, "normal attribute #{prefix}: #{value.inspect}")
      next
    end

    unless ui.confirm format(node, "Do you want to delete #{value.inspect}")
      next
    end

    if deleted = extractor.delete(prefix)
      node.save
      ui.msg format(node, "deleted normal attribute #{deleted.inspect}")
    else
      ui.msg format(node, "could not delete normal attribute #{prefix}")
    end
  end
end

Protected Instance Methods

format(node, text) click to toggle source
# File lib/chef/knife/scrub_attributes.rb, line 82
def format(node, text)
  "#{ui.color(node.name, :cyan)}: #{text}"
end