Class: Byebug::SetCommand
Overview
Implements byebug “set” command.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
commands, find, format_subcmd, format_subcmds, inherited, #initialize, load_commands, #match
Class Method Details
.description ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/byebug/commands/set.rb', line 49
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(setting = nil) ⇒ Object
65
66
67
68
69
|
# File 'lib/byebug/commands/set.rb', line 65
def help(setting = nil)
return "set #{setting.to_sym} <value>\n\n#{setting.help}" if setting
description + Setting.format()
end
|
.names ⇒ Object
45
46
47
|
# File 'lib/byebug/commands/set.rb', line 45
def names
%w(set)
end
|
Instance Method Details
#execute ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/byebug/commands/set.rb', line 11
def execute
key, value = @match[:setting], @match[:value]
return print SetCommand.help if key.nil? && value.nil?
full_key = Setting.find(key)
return print "Unknown setting :#{key}\n" unless full_key
if !Setting.boolean?(full_key) && value.nil?
return print "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)
return unless value = get_int(value, full_key, 1, 300)
end
Setting[full_key.to_sym] = value
return print Setting.settings[full_key.to_sym].to_s
end
|
#get_onoff(arg, default) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/byebug/commands/set.rb', line 31
def get_onoff(arg, default)
return default if arg.nil?
case arg
when '1', 'on'
return true
when '0', 'off'
return false
else
print "Expecting 'on', 1, 'off', or 0. Got: #{arg}.\n"
raise RuntimeError
end
end
|
#regexp ⇒ Object
7
8
9
|
# File 'lib/byebug/commands/set.rb', line 7
def regexp
/^\s* set (?:\s+(?<setting>\w+))? (?:\s+(?<value>\S+))? \s*$/x
end
|