class Cl::Parser::Format
Constants
- NAME
Public Instance Methods
aliases()
click to toggle source
# File lib/cl/parser/format.rb, line 29 def aliases opt.aliases.map { |name| "--#{name} #{ name.upcase unless opt.flag?}".strip } end
collect(strs, mod)
click to toggle source
# File lib/cl/parser/format.rb, line 33 def collect(strs, mod) strs = strs + strs.map { |str| send(mod, str) } strs.flatten.uniq end
dashed(str)
click to toggle source
# File lib/cl/parser/format.rb, line 42 def dashed(str) str =~ NAME && str.sub("#{$1}#{$2}", "#{$1}#{$2.tr('_', '-')}") || str end
flag?()
click to toggle source
# File lib/cl/parser/format.rb, line 58 def flag? opt.flag? && !opt.help? end
long(str)
click to toggle source
# File lib/cl/parser/format.rb, line 11 def long(str) strs = [unnegate(str)] strs = strs.map { |str| negated(str) }.flatten if flag? strs = collect(strs, :dashed) strs = collect(strs, :underscored) strs = collect(strs, :valued) if flag? && Cl.flag_values strs.uniq end
long?(str)
click to toggle source
# File lib/cl/parser/format.rb, line 54 def long?(str) str.start_with?('--') end
negated(str)
click to toggle source
# File lib/cl/parser/format.rb, line 38 def negated(str) str.dup.insert(2, '[no-]') end
short(str)
click to toggle source
# File lib/cl/parser/format.rb, line 20 def short(str) str = "#{str} #{opt.name.upcase}" unless opt.flag? || str.include?(' ') str end
strs()
click to toggle source
# File lib/cl/parser/format.rb, line 6 def strs strs = opt.strs + aliases strs.map { |str| long?(str) ? long(str) : short(str) }.flatten end
underscored(str)
click to toggle source
# File lib/cl/parser/format.rb, line 46 def underscored(str) str =~ NAME && str.sub("#{$1}#{$2}", "#{$1}#{$2.tr('-', '_')}") || str end
unnegate(str)
click to toggle source
# File lib/cl/parser/format.rb, line 25 def unnegate(str) str.sub('--[no-]', '--') end
valued(str)
click to toggle source
# File lib/cl/parser/format.rb, line 50 def valued(str) "#{str} [true|false|yes|no]" end