Class: Bake::Command::List
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Bake::Command::List
- Defined in:
- lib/bake/command/list.rb
Instance Method Summary collapse
- #call ⇒ Object
- #format_parameters(parameters, terminal) ⇒ Object
- #format_recipe(recipe, terminal) ⇒ Object
- #print_scope(terminal, scope, printed: false) ⇒ Object
Instance Method Details
#call ⇒ Object
90 91 92 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 |
# File 'lib/bake/command/list.rb', line 90 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
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 = "**#{name}" 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, printed: false) ⇒ Object
55 56 57 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 |
# File 'lib/bake/command/list.rb', line 55 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 |