# class Chef::Knife::TagDelete

### Public Instance Methods

run() click to toggle source

    # File lib/chef/knife/tag_delete.rb, line 33
    def run
      name = @name_args[0]
      tags = @name_args[1..-1]

      if name.nil? || tags.nil? || tags.empty?
        show_usage
        ui.fatal("You must specify a node name and at least one tag.")
        exit 1
      end

      node = Chef::Node.load name
      deleted_tags = Array.new
      tags.each do |tag|
        unless node.tags.delete(tag).nil?
          deleted_tags << tag
        end
      end
      node.save
      message = if deleted_tags.empty?
                  "Nothing has changed. The tags requested to be deleted do not exist."
                else
                  "Deleted tags #{deleted_tags.join(", ")} for node #{name}."
                end
      ui.info(message)
    end