Class: Ukiryu::Extractors::HelpParser
- Inherits:
-
BaseExtractor
- Object
- BaseExtractor
- Ukiryu::Extractors::HelpParser
- 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
-
#available? ⇒ Boolean
Check if the tool has help output.
-
#extract ⇒ String?
Extract definition by parsing help output.
Methods inherited from BaseExtractor
Constructor Details
This class inherits a constructor from Ukiryu::Extractors::BaseExtractor
Instance Method Details
#available? ⇒ Boolean
Check if the tool has help 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 |
#extract ⇒ String?
Extract definition by parsing help output
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 |