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, #deindent, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



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

def self.description
  <<-DESCRIPTION
    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.
  DESCRIPTION
end

.helpObject



38
39
40
# File 'lib/byebug/commands/set.rb', line 38

def self.help
  super + Setting.help_all
end

.regexpObject



16
17
18
# File 'lib/byebug/commands/set.rb', line 16

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

.short_descriptionObject



34
35
36
# File 'lib/byebug/commands/set.rb', line 34

def self.short_description
  "Modifies byebug settings"
end

Instance Method Details

#executeObject



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

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, /^no/.match?(key) ? 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