def run
      queue = ChimpQueue.instance

      arguments = []

      ARGV.each { |arg| arguments << arg.clone }

      self.cli_args=arguments.collect {|param|
        param.gsub(/(?<==).*/) do |match|
          match='"'+match+'"'
        end
      }.join(" ")


      parse_command_line if @interactive

      check_option_validity if @interactive
      disable_logging unless @@verbose


      puts "chimp #{VERSION} executing..." if (@interactive and not @use_chimpd) and not @@quiet

      #
      # Wait for chimpd to complete tasks
      #
      if @chimpd_wait_until_done
        chimpd_wait_until_done
        exit
      end

      #
      # Send the command to chimpd for execution
      #
      if @use_chimpd
        timestamp = Time.now.to_i
        length = 6
        self.job_uuid = (36**(length - 1) + rand(36**length - 36**(length - 1))).to_s(36)
        ChimpDaemonClient.submit(@chimpd_host, @chimpd_port, self, job_uuid)
        exit
      else
        # Connect to the Api
        Connection.instance
        if @interactive
          Connection.connect
        else
          Connection.connect_and_cache
        end
      end

      # If we're processing the command ourselves, then go
      # ahead and start making API calls to select the objects
      # to operate upon
      #

      # Get elements if --array has been passed
      get_array_info

      # Get elements if we are searching by tags
      get_server_info

      # At this stage @servers should be populated with our findings
      # Get ST info for all elements
      if not @servers.empty?
        get_template_info unless @servers.empty?

        puts "Looking for the rightscripts (This might take some time)" if (@interactive and not @use_chimpd) and not @@quiet
        get_executable_info
      end

      if Chimp.failure
        #This is the failure point when executing standalone
        Log.error "##################################################"
        Log.error "[#{Chimp.get_job_uuid}] API CALL FAILED FOR:"
        Log.error "[#{Chimp.get_job_uuid}] chimp #{@cli_args} "
        Log.error "[#{Chimp.get_job_uuid}] Run manually!"
        Log.error "##################################################"
        exit 1
      end
      #
      # Optionally display the list of objects to operate on
      # and prompt the user
      #
      if @prompt and @interactive
        list_of_objects = make_human_readable_list_of_objects
        confirm = (list_of_objects.size > 0 and @action != :action_none) or @action == :action_none

        if @script_to_run.nil?
          verify("Your command will be executed on the following:", list_of_objects, confirm)
        else
          verify("Your command \""+@script_to_run.params['right_script']['name']+"\" will be executed on the following:", list_of_objects, confirm)
        end
      end
      #
      # Load the queue with work
      #
      if not @servers.first.nil? and ( not @executable.nil? or @action == :action_ssh or @action == :action_report)
        jobs = generate_jobs(@servers, @server_template, @executable)
        add_to_queue(jobs)
      end

      #
      # Exit early if there is nothing to do
      #
      if @action == :action_none or ( queue.group[@group].nil? || queue.group[@group].size == 0)
        puts "No actions to perform." unless self.quiet
      else
        do_work
      end
    end
def run
      queue = ChimpQueue.instance

      arguments = []

      ARGV.each { |arg| arguments << arg.clone }

      self.cli_args=arguments.collect {|param|
        param.gsub(/(?<==).*/) do |match|
          match='"'+match+'"'
        end
      }.join(" ")


      parse_command_line if @interactive

      check_option_validity if @interactive
      disable_logging unless @@verbose


      puts "chimp #{VERSION} executing..." if (@interactive and not @use_chimpd) and not @@quiet

      #
      # Wait for chimpd to complete tasks
      #
      if @chimpd_wait_until_done
        chimpd_wait_until_done
        exit
      end

      #
      # Send the command to chimpd for execution
      #
      if @use_chimpd
        timestamp = Time.now.to_i
        length = 6
        self.job_uuid = (36**(length - 1) + rand(36**length - 36**(length - 1))).to_s(36)
        ChimpDaemonClient.submit(@chimpd_host, @chimpd_port, self, job_uuid)
        exit
      else
        # Connect to the Api
        Connection.instance
        if @interactive
          Connection.connect
        else
          Connection.connect_and_cache
        end
      end

      # If we're processing the command ourselves, then go
      # ahead and start making API calls to select the objects
      # to operate upon
      #

      # Get elements if --array has been passed
      get_array_info

      # Get elements if we are searching by tags
      get_server_info

      # At this stage @servers should be populated with our findings
      # Get ST info for all elements
      if not @servers.empty?
        get_template_info unless @servers.empty?

        puts "Looking for the rightscripts (This might take some time)" if (@interactive and not @use_chimpd) and not @@quiet
        get_executable_info
      end

      if Chimp.failure
        #This is the failure point when executing standalone
        Log.error "##################################################"
        Log.error "[#{Chimp.get_job_uuid}] API CALL FAILED FOR:"
        Log.error "[#{Chimp.get_job_uuid}] chimp #{@cli_args} "
        Log.error "[#{Chimp.get_job_uuid}] Run manually!"
        Log.error "##################################################"
        exit 1
      end
      #
      # Optionally display the list of objects to operate on
      # and prompt the user
      #
      if @prompt and @interactive
        list_of_objects = make_human_readable_list_of_objects
        confirm = (list_of_objects.size > 0 and @action != :action_none) or @action == :action_none

        if @script_to_run.nil?
          verify("Your command will be executed on the following:", list_of_objects, confirm)
        else
          verify("Your command \""+@script_to_run.params['right_script']['name']+"\" will be executed on the following:", list_of_objects, confirm)
        end
      end
      #
      # Load the queue with work
      #
      if not @servers.first.nil? and ( not @executable.nil? or @action == :action_ssh or @action == :action_report)
        jobs = generate_jobs(@servers, @server_template, @executable)
        add_to_queue(jobs)
      end

      #
      # Exit early if there is nothing to do
      #
      if @action == :action_none or ( queue.group[@group].nil? || queue.group[@group].size == 0)
        puts "No actions to perform." unless self.quiet
      else
        do_work
      end
    end
Set up reasonable defaults


 Entry point for the chimp command line application