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



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/bake/command/list.rb', line 93

def call
  first = true
  terminal = @parent.terminal
  context = @parent.context
  
  if scope = context.scope
    printed = print_scope(terminal, context.scope) do
      terminal.print_line(:context, context)
    end
    
    if printed
      terminal.print_line
    end
  end
  
  context.loaders.each do |loader|
    printed = false
    
    loader.each do |path|
      if scope = loader.scope_for(path)
        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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bake/command/list.rb', line 32

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



50
51
52
53
54
55
56
# File 'lib/bake/command/list.rb', line 50

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


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bake/command/list.rb', line 58

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