Class: Ace::Bundle::CLI::Commands::Load

Inherits:
Support::Cli::Command
  • Object
show all
Includes:
Support::Cli::Base
Defined in:
lib/ace/bundle/cli/commands/load.rb

Overview

ace-support-cli Command class for the load command

Loads context from preset, file, or protocol URL

Instance Method Summary collapse

Instance Method Details

#call(input: nil, **options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ace/bundle/cli/commands/load.rb', line 90

def call(input: nil, **options)
  # Handle --help/-h passed as input argument
  if input == "--help" || input == "-h"
    # ace-support-cli will handle this
    return
  end

  if options[:version]
    puts "ace-bundle #{Ace::Bundle::VERSION}"
    return
  end

  if options[:list_presets]
    presets = Ace::Bundle.list_presets
    Atoms::PresetListFormatter.format(presets).each { |line| puts line }
    return
  end

  # Type-convert numeric options using Base helper for proper validation
  # coerce_types uses Integer() which raises ArgumentError on invalid input
  # (unlike .to_i which silently returns 0)
  coerce_types(options, max_size: :integer, timeout: :integer)

  # Handle repeatable options (type: :array returns array, single values need wrapping)
  # --preset returns array when used multiple times, nil otherwise
  if options[:preset] && options[:presets]
    # If both --preset and --presets provided, merge them
    presets = [options[:preset]].flatten + options[:presets].split(",")
    options[:preset] = presets.map(&:strip)
  elsif options[:presets]
    options[:preset] = options[:presets].split(",").map(&:strip)
  elsif options[:preset]
    # Ensure array even for single value
    options[:preset] = [options[:preset]].flatten
  end

  # Same for file option
  options[:file] = [options[:file]].flatten if options[:file]

  # Normalize --compressor toggle
  if options.key?(:compressor) && options[:compressor]
    val = options[:compressor].to_s.downcase
    options[:compressor] = case val
    when "true", "yes", "on", "1" then "on"
    when "false", "no", "off", "0" then "off"
    else val
    end
  end

  # Normalize compressor_source_scope option
  if options.key?(:compressor_source_scope) && options[:compressor_source_scope]
    val = options[:compressor_source_scope].to_s.downcase
    options[:compressor_source_scope] = case val
    when "true", "yes", "on", "" then "per-source"
    when "false", "no", "off" then "off"
    else val
    end
  end

  execute(input, options)
end