lib/dry/cli/option.rb in dry-cli-0.5.0 vs lib/dry/cli/option.rb in dry-cli-0.5.1
- old
+ new
@@ -84,11 +84,10 @@
end
# @since 0.1.0
# @api private
#
- # rubocop:disable Metrics/AbcSize
def parser_options
dasherized_name = Inflector.dasherize(name)
parser_options = []
if boolean?
@@ -98,21 +97,23 @@
parser_options << "--#{dasherized_name} #{name}"
end
parser_options << Array if array?
parser_options << values if values
- parser_options.unshift(alias_name) unless alias_name.nil?
+ parser_options.unshift(*alias_names) if aliases.any?
parser_options << desc if desc
parser_options
end
- # rubocop:enable Metrics/AbcSize
- private
-
# @since 0.1.0
# @api private
- def alias_name
- aliases.join(' ') if aliases.any?
+ def alias_names
+ aliases
+ .map { |name| name.gsub(/^-{1,2}/, '') }
+ .compact
+ .uniq
+ .map { |name| name.size == 1 ? "-#{name}" : "--#{name}" }
+ .map { |name| boolean? ? name : "#{name} VALUE" }
end
end
# Command line argument
#