Class: Byebug::SetCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::ParseHelper
Defined in:
lib/byebug/commands/set.rb

Overview

Change byebug settings.

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?

Methods inherited from Command

#arguments, columnize, #context, #frame, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/byebug/commands/set.rb', line 18

def self.description
  <<-EOD
    set <setting> <value>

    #{short_description}

    Boolean values take "on", "off", "true", "false", "1" or "0". If you
    don't specify a value, the boolean setting will be enabled. Conversely,
    you can use "set no<setting>" to disable them.

    You can see these environment settings with the "show" command.
  EOD
end

.helpObject



36
37
38
# File 'lib/byebug/commands/set.rb', line 36

def self.help
  super + Setting.help_all
end

.regexpObject



14
15
16
# File 'lib/byebug/commands/set.rb', line 14

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

.short_descriptionObject



32
33
34
# File 'lib/byebug/commands/set.rb', line 32

def self.short_description
  'Modifies byebug settings'
end

Instance Method Details

#executeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/byebug/commands/set.rb', line 40

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

  setting = Setting.find(key)
  return errmsg(pr('set.errors.unknown_setting', key: key)) unless setting

  if !setting.boolean? && value.nil?
    err = pr('set.errors.must_specify_value', key: key)
  elsif setting.boolean?
    value, err = get_onoff(value, key =~ /^no/ ? false : true)
  elsif setting.integer?
    value, err = get_int(value, setting.to_sym, 1)
  end
  return errmsg(err) if value.nil?

  setting.value = value

  puts setting.to_s
end