# class Chef::Knife::NodeRunListSet

### Public Instance Methods

run() click to toggle source

    # File lib/chef/knife/node_run_list_set.rb, line 32
    def run
      if @name_args.size < 2
        ui.fatal "You must supply both a node name and a run list."
        show_usage
        exit 1
      elsif @name_args.size > 2
        # Check for nested lists and create a single plain one
        entries = @name_args[1..-1].map do |entry|
          entry.split(',').map { |e| e.strip }
        end.flatten
      else
        # Convert to array and remove the extra spaces
        entries = @name_args[1].split(',').map { |e| e.strip }
      end
      node = Chef::Node.load(@name_args[0])

      set_run_list(node, entries)

      node.save

      config[:run_list] = true

      output(format_for_display(node))
    end

set_run_list(node, entries) click to toggle source

Clears out any existing run_list_items and sets them to the specified entries

    # File lib/chef/knife/node_run_list_set.rb, line 59
    def set_run_list(node, entries)
      node.run_list.run_list_items.clear
      entries.each { |e| node.run_list << e }
    end