<commit_before>module Byebug
  #
  # Change byebug settings.
  #
  class SetCommand < Command
    self.allow_in_control = true

    def regexp
      /^\s* set (?:\s+(?<setting>\w+))? (?:\s+(?<value>\S+))? \s*$/x
    end

    def execute
      key, value = @match[:setting], @match[:value]
      return print(SetCommand.help) if key.nil? && value.nil?

      full_key = Setting.find(key)
      return errmsg("Unknown setting :#{key}") unless full_key

      if !Setting.boolean?(full_key) && value.nil?
        return errmsg("You must specify a value for setting :#{key}\n")
      elsif Setting.boolean?(full_key)
        value = get_onoff(value, key =~ /^no/ ? false : true)
      elsif Setting.integer?(full_key)
        value, err = get_int(value, full_key, 1)
        return errmsg(err) unless value
      end

      Setting[full_key.to_sym] = value

      print Setting.settings[full_key.to_sym].to_s
    end

    def get_onoff(arg, default)
      return default if arg.nil?

      case arg
      when '1', 'on', 'true'
        true
      when '0', 'off', 'false'
        false
      else
        print "Expecting 'on', 1, true, 'off', 0, false. Got: #{arg}.\n"
        fail RuntimeError
      end
    end

    class << self
      def names
        %w(set)
      end

      def description
        <<-EOD.gsub(/^        /, '')

          set <setting> <value>

          Modifies parts of byebug environment.

          Boolean values take "on", "off", "true", "false", "1" or "0". If you<commit_msg>Refactor<commit_after>module Byebug
  #
  # Change byebug settings.
  #
  class SetCommand < Command
    self.allow_in_control = true

    def regexp
      /^\s* set (?:\s+(?<setting>\w+))? (?:\s+(?<value>\S+))? \s*$/x
    end

    def execute
      key, value = @match[:setting], @match[:value]
      return print(SetCommand.help) if key.nil? && value.nil?

      full_key = Setting.find(key)
      return errmsg("Unknown setting :#{key}") unless full_key

      if !Setting.boolean?(full_key) && value.nil?
        value, err = nil, "You must specify a value for setting :#{key}"
      elsif Setting.boolean?(full_key)
        value, err = get_onoff(value, key =~ /^no/ ? false : true)
      elsif Setting.integer?(full_key)
        value, err = get_int(value, full_key, 1)
      end
      return errmsg(err) if value.nil?


      Setting[full_key.to_sym] = value

      print Setting.settings[full_key.to_sym].to_s
    end

    def get_onoff(arg, default)
      return default if arg.nil?

      case arg
      when '1', 'on', 'true'
        true
      when '0', 'off', 'false'
        false
      else
        [nil, "Expecting 'on', 1, true, 'off', 0, false. Got: #{arg}.\n"]
      end
    end

    class << self
      def names
        %w(set)
      end

      def description
        <<-EOD.gsub(/^        /, '')

          set <setting> <value>

          Modifies parts of byebug environment.

          Boolean values take "on", "off", "true", "false", "1" or "0". If you
{'fraction_non_alphanumeric': 0.1427613941018767, 'fraction_numerical': 0.004691689008042895, 'mean_word_length': 2.1355042016806722, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '5739026', 'n_tokens_mistral': 1012, 'n_tokens_neox': 986, 'n_words': 274}