Class: Bake::Command::List
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Bake::Command::List
- Defined in:
- lib/bake/command/list.rb
Constant Summary collapse
- PARAMETER =
/@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\Z/
Instance Method Summary collapse
- #call ⇒ Object
- #format_parameters(parameters, terminal) ⇒ Object
- #format_recipe(recipe, terminal) ⇒ Object
- #print_scope(terminal, scope) ⇒ Object
Instance Method Details
#call ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bake/command/list.rb', line 76 def call first = true terminal = @parent.terminal context = @parent.context if scope = context.scope terminal.print_line(:context, context) print_scope(terminal, context.scope) terminal.print_line end context.loaders.each do |loader| terminal.print_line(:loader, loader) loader.each do |path| if scope = loader.scope_for(path) print_scope(terminal, scope) end end terminal.print_line end end |
#format_parameters(parameters, terminal) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bake/command/list.rb', line 29 def format_parameters(parameters, terminal) parameters.each do |type, name| case type when :key name = "#{name}=" when :keyreq name = "#{name}=" when :keyrest name = "**options" else name = name.to_s end terminal.print(:reset, " ") terminal.print(type, name) end end |
#format_recipe(recipe, terminal) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/bake/command/list.rb', line 47 def format_recipe(recipe, terminal) terminal.print(:command, recipe.command) if parameters = recipe.parameters format_parameters(parameters, terminal) end end |
#print_scope(terminal, scope) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bake/command/list.rb', line 55 def print_scope(terminal, scope) format_recipe = self.method(:format_recipe).curry scope.recipes.sort_by(&:command).each do |recipe| terminal.print_line terminal.print_line("\t", format_recipe[recipe]) recipe.description.each do |line| if match = line.match(PARAMETER) terminal.print_line("\t\t", :parameter, match[:name], :reset, " [", :type, match[:type], :reset, "] ", :description, match[:details] ) else terminal.print_line("\t\t", :description, line) end end end end |