Sha256: c6036cc381ec4e0f0686863c79637dce9740a39e6fbf70cd179b23c30285e3b5

Contents?: true

Size: 1.7 KB

Versions: 202

Compression:

Stored size: 1.7 KB

Contents

#
# Author:: Ryan Davis (<ryand-ruby@zenspider.com>)
# Author:: Daniel DeLeo (<dan@opscode.com>)
# Author:: Nuo Yan (<nuo@opscode.com>)
# Copyright:: Copyright (c) 2011 Ryan Davis and Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/knife'

class Chef
  class Knife
    class TagDelete < Knife

      deps do
        require 'chef/node'
      end

      banner "knife tag delete NODE TAG ..."

      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
    end
  end
end

Version data entries

202 entries across 202 versions & 2 rubygems

Version Path
chef-12.6.0 lib/chef/knife/tag_delete.rb
chef-12.6.0-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.5.1-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.5.1 lib/chef/knife/tag_delete.rb
chef-12.4.3-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.4.3 lib/chef/knife/tag_delete.rb
chef-12.4.2-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.4.2 lib/chef/knife/tag_delete.rb
chef-12.5.0.alpha.1 lib/chef/knife/tag_delete.rb
chef-12.4.1-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.4.1 lib/chef/knife/tag_delete.rb
chef-12.4.0 lib/chef/knife/tag_delete.rb
chef-12.4.0-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.4.0.rc.2 lib/chef/knife/tag_delete.rb
chef-12.4.0.rc.2-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-12.4.0.rc.0 lib/chef/knife/tag_delete.rb
chef-12.4.0.rc.0-universal-mingw32 lib/chef/knife/tag_delete.rb
chef-11.18.12-x86-mingw32 lib/chef/knife/tag_delete.rb
chef-11.18.12 lib/chef/knife/tag_delete.rb
chef-12.3.0-x86-mingw32 lib/chef/knife/tag_delete.rb