Class: Byebug::SetCommand

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

Overview

Change byebug settings.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/byebug/commands/set.rb', line 51

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

    set <setting> <value>

    Modifies parts of byebug environment.

    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

.help(subcmds = []) ⇒ Object



66
67
68
# File 'lib/byebug/commands/set.rb', line 66

def help(subcmds = [])
  Setting.help('set', subcmds.first)
end

.namesObject



47
48
49
# File 'lib/byebug/commands/set.rb', line 47

def names
  %w(set)
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/byebug/commands/set.rb', line 12

def execute
  key, value = @match[:setting], @match[:value]
  return puts(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

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

#get_onoff(arg, default) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/byebug/commands/set.rb', line 33

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

#regexpObject



8
9
10
# File 'lib/byebug/commands/set.rb', line 8

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