<commit_before>require_relative 'base'

module WavefrontCli
  #
  # CLI coverage for the v2 'alert' API.
  #
  class Alert < WavefrontCli::Base
    def do_describe
      wf.describe(options[:'<id>'], options[:version])
    end

    def do_snooze
      wf.snooze(options[:'<id>'], options[:time])
    end

    def do_unsnooze
      wf.unsnooze(options[:'<id>'])
    end

    def do_delete
      word = if wf.describe(options[:'<id>']).status.code == 200
               'Soft'
             else
               'Permanently'
             end

      puts "#{word} deleting alert '#{options[:'<id>']}'."
      wf.delete(options[:'<id>'])
    end

    def do_summary
      wf.summary
    end

    def do_history
      wf.history(options[:'<id>'], options[:offset], options[:limit])
    end

    def do_currently
      state = options[:'<state>'].to_s

      if wf.respond_to?(state)
        in_state(state)
      else
        abort format("'%s' is not a valid alert state.", state)
      end
    end

    def do_firing
      in_state(:firing)
    end

    def do_snoozed
      in_state(:firing)
    end

    def do_queries
      resp, data = one_or_all

      resp.tap do |r|
        r.response.items = data.map do |a|
          { id: a.id, condition: a.condition }
        end
      end
    end

    def do_install
      wf.install(options[:'<id>'])
    end

    def do_uninstall
      wf.uninstall(options[:'<id>'])
    end

    # How many alerts are in the given state? If none, say so,
    # rather than just printing nothing.
    #
    def in_state(status)
      options[:all] = true
      ret = find_in_state(status)<commit_msg>alert snoozed and firing did the same thing<commit_after>require_relative 'base'

module WavefrontCli
  #
  # CLI coverage for the v2 'alert' API.
  #
  class Alert < WavefrontCli::Base
    def do_describe
      wf.describe(options[:'<id>'], options[:version])
    end

    def do_snooze
      wf.snooze(options[:'<id>'], options[:time])
    end

    def do_unsnooze
      wf.unsnooze(options[:'<id>'])
    end

    def do_delete
      word = if wf.describe(options[:'<id>']).status.code == 200
               'Soft'
             else
               'Permanently'
             end

      puts "#{word} deleting alert '#{options[:'<id>']}'."
      wf.delete(options[:'<id>'])
    end

    def do_summary
      wf.summary
    end

    def do_history
      wf.history(options[:'<id>'], options[:offset], options[:limit])
    end

    def do_currently
      state = options[:'<state>'].to_s

      if wf.respond_to?(state)
        in_state(state)
      else
        abort format("'%s' is not a valid alert state.", state)
      end
    end

    def do_firing
      in_state(:firing)
    end

    def do_snoozed
      in_state(:snoozed)
    end

    def do_queries
      resp, data = one_or_all

      resp.tap do |r|
        r.response.items = data.map do |a|
          { id: a.id, condition: a.condition }
        end
      end
    end

    def do_install
      wf.install(options[:'<id>'])
    end

    def do_uninstall
      wf.uninstall(options[:'<id>'])
    end

    # How many alerts are in the given state? If none, say so,
    # rather than just printing nothing.
    #
    def in_state(status)
      options[:all] = true
      ret = find_in_state(status)
{'fraction_non_alphanumeric': 0.12290842713720718, 'fraction_numerical': 0.002433830240340736, 'mean_word_length': 2.0786516853932584, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1652293', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1097, 'n_words': 270}