Class: Bake::Command::List

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/bake/command/list.rb

Overview

List all available commands.

Instance Method Summary collapse

Instance Method Details

#callObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/bake/command/list.rb', line 78

def call
  first = true
  terminal = @parent.terminal
  context = @parent.context
  
  context.registry.each do |loader|
    printed = false
    
    loader.each do |path|
      loader.scopes_for(path) do |scope|
        print_scope(terminal, scope, printed: printed) do
          terminal.print_line(:loader, loader)
          printed = true
        end
      end
    end
    
    if printed
      terminal.print_line
    end
  end
end

#format_parameters(parameters, terminal) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bake/command/list.rb', line 17

def format_parameters(parameters, terminal)
  parameters.each do |type, name|
    case type
    when :key
      name = "#{name}="
    when :keyreq
      name = "#{name}="
    when :keyrest
      name = "**#{name}"
    else
      name = name.to_s
    end
    
    terminal.print(:reset, " ")
    terminal.print(type, name)
  end
end

#format_recipe(recipe, terminal) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/bake/command/list.rb', line 35

def format_recipe(recipe, terminal)
  terminal.print(:command, recipe.command)
  
  if parameters = recipe.parameters
    format_parameters(parameters, terminal)
  end
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bake/command/list.rb', line 43

def print_scope(terminal, scope, printed: false)
  format_recipe = self.method(:format_recipe).curry
  
  scope.recipes.sort.each do |recipe|
    if @pattern and !recipe.command.include?(pattern)
      next
    end
    
    unless printed
      yield
    
      printed = true
    end
    
    terminal.print_line
    terminal.print_line("\t", format_recipe[recipe])
    
    documentation = recipe.documentation
    
    documentation.description do |line|
      terminal.print_line("\t\t", :description, line)
    end
    
    documentation.parameters do |parameter|
      terminal.print_line("\t\t",
        :parameter, parameter[:name], :reset, " [",
        :type, parameter[:type], :reset, "] ",
        :description, parameter[:details]
      )
    end
  end
  
  return printed
end