Class: Udb::CliCommands::Show

Inherits:
SubCommandBase show all
Includes:
Thor::Actions
Defined in:
lib/udb/cli.rb

Instance Method Summary collapse

Methods inherited from SubCommandBase

banner, subcommand_prefix

Instance Method Details

#extension(ext_name) ⇒ Object

Raises:

  • (ArgumentError)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/udb/cli.rb', line 144

def extension(ext_name)
  raise ArgumentError, "Arch directory does not exist: #{options[:arch]}" unless File.directory?(options[:arch])

  cfg_file =
    if File.file?(options[:config])
      Pathname.new(options[:config])
    elsif File.file?("#{options[:config_dir]}/#{options[:config]}.yaml")
      Pathname.new("#{options[:config_dir]}/#{options[:config]}.yaml")
    else
      raise ArgumentError, "Cannot find config: #{options[:config]}"
    end

  resolver =
    Udb::Resolver.new(
      std_path_override: Pathname.new(options[:arch]),
      gen_path_override: Pathname.new(options[:gen]),
      custom_path_override: Pathname.new(options[:arch_overlay])
    )
  cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)
  ext = cfg_arch.extension(ext_name)
  if ext.nil?
    say "Could not find an extension named '#{ext_name}'", :red
  else
    say <<~INFO
      #{ext.name} Extension
        #{ext.long_name}

      Versions:
      #{ext.versions.map { |ext_ver| "  * #{ext_ver.version_str}" }.join("\n") }

    INFO
    say "Includes #{ext.instructions.count} instructions" if ext.instructions.count.positive?
  end
end

#parameter(param_name) ⇒ Object

Raises:

  • (ArgumentError)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/udb/cli.rb', line 185

def parameter(param_name)
  raise ArgumentError, "Arch directory does not exist: #{options[:arch]}" unless File.directory?(options[:arch])

  cfg_file =
    if File.file?(options[:config])
      Pathname.new(options[:config])
    elsif File.file?("#{options[:config_dir]}/#{options[:config]}.yaml")
      Pathname.new("#{options[:config_dir]}/#{options[:config]}.yaml")
    else
      raise ArgumentError, "Cannot find config: #{options[:config]}"
    end

  resolver =
    Udb::Resolver.new(
      std_path_override: Pathname.new(options[:arch]),
      gen_path_override: Pathname.new(options[:gen]),
      custom_path_override: Pathname.new(options[:arch_overlay])
    )
  cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)
  param = cfg_arch.param(param_name)
  if param.nil?
    say "Could not find parameter named #{param_name}"
  else
    say <<~INFO
      #{param_name}

        Defined by:
        #{param.defined_by_condition.to_s_pretty}

        Description:
          #{param.description.gsub("\n", "\n    ")}

        Value:
          #{param.schema.to_pretty_s}
    INFO
  end
end