class Convoy::Formatter::Option
Attributes
context[R]
details[R]
name[R]
setup[R]
Public Class Methods
new(name, details, setup, context)
click to toggle source
# File lib/convoy/formatter/option.rb, line 6 def initialize(name, details, setup, context) @name = name.to_sym @details = details @setup = setup @context = context end
Public Instance Methods
conflicts()
click to toggle source
# File lib/convoy/formatter/option.rb, line 25 def conflicts has_conflicts? ? "conflicts with: #{conflicts_list.map { |option| "--#{option}" }.join(', ')}" : '' end
dependencies()
click to toggle source
# File lib/convoy/formatter/option.rb, line 33 def dependencies has_dependencies? ? "depends on: #{format_dependency_list(dependencies_list).join(', ')}" : '' end
description()
click to toggle source
# File lib/convoy/formatter/option.rb, line 17 def description [base_description_string, description_default_string].select { |item| !item.empty? }.join(" ") end
has_conflicts?()
click to toggle source
# File lib/convoy/formatter/option.rb, line 21 def has_conflicts? !conflicts_list.empty? end
has_dependencies?()
click to toggle source
# File lib/convoy/formatter/option.rb, line 29 def has_dependencies? !dependencies_list.empty? end
has_validations?()
click to toggle source
# File lib/convoy/formatter/option.rb, line 37 def has_validations? !validations_list.empty? end
usage()
click to toggle source
# File lib/convoy/formatter/option.rb, line 13 def usage [short_string, long_string, type_string].select { |item| !item.empty? }.join(', ') end
validations()
click to toggle source
# File lib/convoy/formatter/option.rb, line 41 def validations has_validations? ? validation_messages : [] end
Private Instance Methods
base_description_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 73 def base_description_string details[:desc] || details[:description] || '' end
base_long_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 112 def base_long_string "--#{details[:long]}" end
conflicts_list()
click to toggle source
# File lib/convoy/formatter/option.rb, line 69 def conflicts_list setup.conflicting_options_for(context)[name] || [] end
default_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 85 def default_string case details[:default] when $stdout; "<stdout>" when $stdin; "<stdin>" when $stderr; "<stderr>" when Array details[:default].join(", ") else details[:default].to_s end end
dependencies_list()
click to toggle source
# File lib/convoy/formatter/option.rb, line 65 def dependencies_list setup.dependencies_for(context)[name] || [] end
description_default_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 77 def description_default_string if details[:default] base_description_string =~ /\.$/ ? "(Default: #{default_string})" : "(default: #{default_string})" else "" end end
flag?()
click to toggle source
# File lib/convoy/formatter/option.rb, line 147 def flag? details[:type] == :flag end
flag_with_default_true?()
click to toggle source
# File lib/convoy/formatter/option.rb, line 143 def flag_with_default_true? flag? && details[:default] end
format_dependency_list(dependency_list)
click to toggle source
# File lib/convoy/formatter/option.rb, line 54 def format_dependency_list(dependency_list) dependencies_list.map do |option| case option when Hash option.inject([]) { |acc, (key, value)| acc << "--#{key}=#{value}" }.join(', ') else "--#{option}" end end end
long_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 104 def long_string if flag_with_default_true? "#{base_long_string}, --no-#{details[:long]}" else base_long_string end end
short_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 100 def short_string details[:short] && details[:short] != :none ? "-#{details[:short]}" : "" end
type_string()
click to toggle source
# File lib/convoy/formatter/option.rb, line 116 def type_string case details[:type] when :flag; "" when :int; "<i>" when :ints; "<i+>" when :string; "<s>" when :strings; "<s+>" when :float; "<f>" when :floats; "<f+>" when :io; "<filename/uri>" when :ios; "<filename/uri+>" when :date; "<date>" when :dates; "<date+>" end end
validation_messages()
click to toggle source
# File lib/convoy/formatter/option.rb, line 46 def validation_messages validations_list.map { |validation| validation[:desc] } end
validations_list()
click to toggle source
# File lib/convoy/formatter/option.rb, line 50 def validations_list setup.validations_for(context)[name] || [] end