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, #match

Methods included from StringFunctions

#camelize, #prettify

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Methods included from ParseFunctions

#get_int, #parse_steps, #syntax_valid?

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject


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

def description
  prettify <<-EOD
    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(subcmd = nil) ⇒ Object


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

def help(subcmd = nil)
  Setting.help('set', subcmd)
end

.namesObject


49
50
51
# File 'lib/byebug/commands/set.rb', line 49

def names
  %w(set)
end

Instance Method Details

#executeObject


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

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

#get_onoff(arg, default) ⇒ Object


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

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

  case arg
  when '1', 'on', 'true'
    true
  when '0', 'off', 'false'
    false
  else
    [nil, pr('set.errors.on_off', arg: arg)]
  end
end

#regexpObject


10
11
12
# File 'lib/byebug/commands/set.rb', line 10

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