Class: AIA::UtilityDirectives

Inherits:
Directive
  • Object
show all
Defined in:
lib/aia/directives/utility_directives.rb

Constant Summary

Constants inherited from Directive

Directive::DIRECTIVE_PREFIX

Instance Method Summary collapse

Methods inherited from Directive

build_dispatch_block, help

Instance Method Details

#help(args = nil, context_manager = nil) ⇒ Object



61
62
63
# File 'lib/aia/directives/utility_directives.rb', line 61

def help(args = nil, context_manager = nil)
  AIA::Directive.help
end

#robot(args, context_manager = nil) ⇒ Object



55
56
57
58
# File 'lib/aia/directives/utility_directives.rb', line 55

def robot(args, context_manager = nil)
  AIA::Utility.robot
  ""
end

#terse(args, context_manager = nil) ⇒ Object



50
51
52
# File 'lib/aia/directives/utility_directives.rb', line 50

def terse(args, context_manager = nil)
  "" # DEPRECATED: terse mode has been removed
end

#tools(args = [], context_manager = nil) ⇒ Object



9
10
11
12
13
14
15
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
# File 'lib/aia/directives/utility_directives.rb', line 9

def tools(args = [], context_manager = nil)
  indent = 4
  spaces = " " * indent
  width = TTY::Screen.width - indent - 2
  filter = args.first&.downcase

  loaded_tools = AIA.config.loaded_tools || []
  if loaded_tools.empty?
    puts "No tools are available"
  else
    tools_to_display = loaded_tools

    if filter
      tools_to_display = tools_to_display.select do |tool|
        name = tool.respond_to?(:name) ? tool.name : tool.class.name
        name.downcase.include?(filter)
      end
    end

    if tools_to_display.empty?
      puts "No tools match the filter: #{args.first}"
    else
      puts
      header = filter ? "Available Tools (filtered by '#{args.first}')" : "Available Tools"
      puts header
      puts "=" * header.length

      tools_to_display.each do |tool|
        name = tool.respond_to?(:name) ? tool.name : tool.class.name
        puts "\n#{name}"
        puts "-" * name.size
        puts WordWrapper::MinimumRaggedness.new(width, tool.description).wrap.split("\n").map { |s| spaces + s + "\n" }.join
      end
    end
  end
  puts

  ''
end