lib/yard/cli/config.rb in yard-0.6.4 vs lib/yard/cli/config.rb in yard-0.6.5
- old
+ new
@@ -10,15 +10,23 @@
attr_accessor :values
# @return [Boolean] whether to reset the {#key}
attr_accessor :reset
+ # @return [Boolean] whether the value being set should be inside a list
+ attr_accessor :as_list
+
+ # @return [Boolean] whether to append values to existing key
+ attr_accessor :append
+
def initialize
super
self.key = nil
self.values = []
self.reset = false
+ self.append = false
+ self.as_list = false
end
def description
'Views or edits current global configuration'
end
@@ -42,11 +50,13 @@
if reset
log.debug "Resetting #{key}"
YARD::Config.options[key] = YARD::Config::DEFAULT_CONFIG_OPTIONS[key]
else
log.debug "Setting #{key} to #{values.inspect}"
- YARD::Config.options[key] = encode_values
+ items, current_items = encode_values, YARD::Config.options[key]
+ items = [current_items].flatten + [items].flatten if append
+ YARD::Config.options[key] = items
end
YARD::Config.save
end
def view_item
@@ -59,11 +69,11 @@
require 'yaml'
puts YAML.dump(YARD::Config.options).sub(/\A--.*\n/, '').gsub(/\n\n/, "\n")
end
def encode_values
- if values.size == 1
+ if values.size == 1 && !as_list
encode_value(values.first)
else
values.map {|v| encode_value(v) }
end
end
@@ -77,10 +87,12 @@
end
end
def optparse(*args)
list = false
+ self.as_list = false
+ self.append = false
opts = OptionParser.new
opts.banner = "Usage: yard config [options] [item [value ...]]"
opts.separator ""
opts.separator "Example: yard config load_plugins true"
opts.separator ""
@@ -98,9 +110,20 @@
list = true
end
opts.on('-r', '--reset', 'Resets the specific item to default') do
self.reset = true
end
+
+ opts.separator ""
+ opts.separator "Modifying keys:"
+
+ opts.on('-a', '--append', 'Appends items to existing key values') do
+ self.append = true
+ end
+ opts.on('--as-list', 'Forces the value(s) to be wrapped in an array') do
+ self.as_list = true
+ end
+
common_options(opts)
parse_options(opts, args)
args = [] if list
self.key = args.shift.to_sym if args.size >= 1
self.values = args if args.size >= 1
\ No newline at end of file