Class: Command::Config
- Inherits:
-
Base
- Object
- Base
- Command::Config
show all
- Defined in:
- lib/command/config.rb
Instance Attribute Summary
Attributes inherited from Base
#status
Instance Method Summary
collapse
Methods inherited from Base
#execute, #initialize
Constructor Details
This class inherits a constructor from Command::Base
Instance Method Details
#define_options ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/command/config.rb', line 6
def define_options
@parser.on("--local") { @options[:file] = :local }
@parser.on("--global") { @options[:file] = :global }
@parser.on("--system") { @options[:file] = :system }
@parser.on "-f <config-file>", "--file=<config-file>" do |file|
@options[:file] = file
end
@parser.on("--add <name>") { |name| @options[:add] = name }
@parser.on("--replace-all <name>") { |name| @options[:replace] = name }
@parser.on("--get-all <name>") { |name| @options[:get_all] = name }
@parser.on("--unset <name>") { |name| @options[:unset] = name }
@parser.on("--unset-all <name>") { |name| @options[:unset_all] = name }
@parser.on "--remove-section <name>" do |name|
@options[:remove_section] = name
end
end
|
#run ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/command/config.rb', line 26
def run
add_variable if @options[:add]
replace_variable if @options[:replace]
get_all_values if @options[:get_all]
unset_single if @options[:unset]
unset_all if @options[:unset_all]
remove_section if @options[:remove_section]
key, value = parse_key(@args[0]), @args[1]
if value
edit_config { |config| config.set(key, value) }
else
read_config { |config| [*config.get(key)] }
end
rescue ::Config::ParseError => error
@stderr.puts "error: #{ error.message }"
exit 3
end
|