Module: Ukiryu::OptionsBuilder::Formatter
- Defined in:
- lib/ukiryu/options_builder/formatter.rb
Overview
Formatting utilities for options, flags, and arguments
This module handles the conversion of option values into shell command arguments according to various format styles.
Class Method Summary collapse
-
.format_arg(value, arg_def, shell_instance) ⇒ String
Format an argument value.
-
.format_flag(flag_def, _shell_instance) ⇒ String?
Format a flag according to its definition.
-
.format_option(opt_def, value, _shell_instance) ⇒ String+
Format an option according to its definition.
Class Method Details
.format_arg(value, arg_def, shell_instance) ⇒ String
Format an argument value
76 77 78 79 80 81 82 |
# File 'lib/ukiryu/options_builder/formatter.rb', line 76 def self.format_arg(value, arg_def, shell_instance) if arg_def.type == :file shell_instance.format_path(value.to_s) else value.to_s end end |
.format_flag(flag_def, _shell_instance) ⇒ String?
Format a flag according to its definition
66 67 68 |
# File 'lib/ukiryu/options_builder/formatter.rb', line 66 def self.format_flag(flag_def, _shell_instance) flag_def.cli || '' end |
.format_option(opt_def, value, _shell_instance) ⇒ String+
Format an option according to its definition
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 |
# File 'lib/ukiryu/options_builder/formatter.rb', line 16 def self.format_option(opt_def, value, _shell_instance) type = opt_def.type # Handle boolean types - just return the CLI flag if [:boolean, TrueClass, 'boolean'].include?(type) return nil if value.nil? || value == false return opt_def.cli || '' end cli = opt_def.cli || '' format = opt_def.format || 'double_dash_equals' format_sym = format.is_a?(String) ? format.to_sym : format value_str = value.is_a?(Symbol) ? value.to_s : value.to_s # Handle array values if value.is_a?(Array) && opt_def.separator joined = value.join(opt_def.separator) return case format_sym when :double_dash_equals "#{cli}#{joined}" when :double_dash_space, :single_dash_space [cli, joined] else "#{cli}#{joined}" end end case format_sym when :double_dash_equals "#{cli}=#{value_str}" when :double_dash_space, :single_dash_space [cli, value_str] when :single_dash_equals "#{cli}=#{value_str}" when :slash_colon "#{cli}:#{value_str}" when :slash_space "#{cli} #{value_str}" else "#{cli}=#{value_str}" end end |