5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/pdk/cli/remove/config.rb', line 5
def self.run(opts, args)
item_name = args.count.positive? ? args[0] : nil
item_value = args.count > 1 ? args[1].strip : nil
item_value = nil if !item_value.nil? && item_value.empty?
force = opts[:force] || false
raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
current_value = PDK.config.get(item_name)
raise PDK::CLI::ExitWithError, format("The configuration item '%{name}' can not be removed.", name: item_name) if current_value.is_a?(PDK::Config::Namespace)
if current_value.nil?
PDK.logger.info(format("Could not remove '%{name}' as it has not been set", name: item_name))
return 0
end
PDK.logger.info(format("Ignoring the item value '%{value}' as --force has been set", value: item_value)) if current_value.is_a?(Array) && !item_value.nil? && force
PDK.logger.info('Ignoring --force as the setting is not multi-valued') if !current_value.is_a?(Array) && force
if current_value.is_a?(Array) && !force
new_value = item_value.nil? ? [] : current_value.reject { |item| item.to_s == item_value }
if current_value.count == new_value.count
if item_value.nil?
PDK.logger.info(format("Could not remove '%{name}' as it is already empty", name: item_name))
else
PDK.logger.info(format("Could not remove '%{value}' from '%{name}' as it has not been set", value: item_value, name: item_name))
end
return 0
end
PDK.config.set(item_name, new_value, force: true)
else
PDK.config.set(item_name, nil, force: true)
end
new_value = PDK.config.get(item_name)
if current_value.is_a?(Array) && !force
if item_value.nil?
PDK.logger.info(format("Cleared '%{name}' which had a value of '%{from}'", name: item_name, from: current_value))
else
PDK.logger.info(format("Removed '%{value}' from '%{name}'", value: item_value, name: item_name))
end
elsif !new_value.nil?
PDK.logger.info(format("Could not remove '%{name}' as it using a default value of '%{to}'", name: item_name, to: new_value))
else
PDK.logger.info(format("Removed '%{name}' which had a value of '%{from}'", name: item_name, from: current_value))
end
$stdout.puts format('%{name}=%{value}', name: item_name, value: new_value)
0
end
|