Class: Ukiryu::Extractors::HelpParser

Inherits:
BaseExtractor show all
Defined in:
lib/ukiryu/extractors/help_parser.rb

Overview

Help parser extraction strategy

Reverse-engineers a tool definition by parsing the output of the tool’s ‘–help` command.

Instance Method Summary collapse

Methods inherited from BaseExtractor

#initialize

Constructor Details

This class inherits a constructor from Ukiryu::Extractors::BaseExtractor

Instance Method Details

#available?Boolean

Check if the tool has help output

Returns:

  • (Boolean)

    true if –help produces output



29
30
31
32
33
34
# File 'lib/ukiryu/extractors/help_parser.rb', line 29

def available?
  return false if command_not_found?

  help_result = execute_command([@tool_name.to_s, '--help'])
  help_result[:exit_status].zero? && !(help_result[:stdout] + help_result[:stderr]).strip.empty?
end

#extractString?

Extract definition by parsing help output

Returns:

  • (String, nil)

    the YAML definition or nil if extraction failed



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ukiryu/extractors/help_parser.rb', line 13

def extract
  return nil unless available?

  help_result = execute_command([@tool_name.to_s, '--help'])
  return nil unless help_result[:exit_status].zero?

  help_text = help_result[:stdout] + help_result[:stderr]
  return nil if help_text.strip.empty?

  # Parse help output and generate YAML
  parse_help_to_yaml(help_text)
end