bake 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bake.rb +0 -4
- data/lib/bake/command/list.rb +40 -19
- data/lib/bake/documentation.rb +80 -0
- data/lib/bake/recipe.rb +16 -16
- data/lib/bake/types/input.rb +42 -0
- data/lib/bake/types/output.rb +42 -0
- data/lib/bake/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 235731a8ee0e63e3ef1cf630809bb5839b55a2abc4ee7e6612c19b179208b465
|
4
|
+
data.tar.gz: c394732e183d146875c650b9c0546302214ef7e6ee2526066fda5aad1612eadc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e965cf9fca9dd37092addd4c24bc58d25712039526504149b3eef7f2f2d594bd6d34de60d8323316c21c1ac8cde81e08487e5b5a52752d426ad1ab65a8ab0d7
|
7
|
+
data.tar.gz: 4280078bf3b331fc0c3057001cb7a276608a2a541ab9f8fbf36378f45b764ff2afe5efdfc1e3a83ac175cd7b769e384dd3aa71ba0034523bc926e45f0fd2f039
|
data/bake.rb
CHANGED
data/lib/bake/command/list.rb
CHANGED
@@ -24,7 +24,7 @@ require 'set'
|
|
24
24
|
module Bake
|
25
25
|
module Command
|
26
26
|
class List < Samovar::Command
|
27
|
-
|
27
|
+
one :pattern, "The pattern to filter tasks by."
|
28
28
|
|
29
29
|
def format_parameters(parameters, terminal)
|
30
30
|
parameters.each do |type, name|
|
@@ -52,25 +52,39 @@ module Bake
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def print_scope(terminal, scope)
|
55
|
+
def print_scope(terminal, scope, printed: false)
|
56
56
|
format_recipe = self.method(:format_recipe).curry
|
57
57
|
|
58
58
|
scope.recipes.sort.each do |recipe|
|
59
|
+
if @pattern and !recipe.command.include?(pattern)
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
63
|
+
unless printed
|
64
|
+
yield
|
65
|
+
|
66
|
+
printed = true
|
67
|
+
end
|
68
|
+
|
59
69
|
terminal.print_line
|
60
70
|
terminal.print_line("\t", format_recipe[recipe])
|
61
71
|
|
62
|
-
recipe.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
documentation = recipe.documentation
|
73
|
+
|
74
|
+
documentation.description do |line|
|
75
|
+
terminal.print_line("\t\t", :description, line)
|
76
|
+
end
|
77
|
+
|
78
|
+
documentation.parameters do |parameter|
|
79
|
+
terminal.print_line("\t\t",
|
80
|
+
:parameter, parameter[:name], :reset, " [",
|
81
|
+
:type, parameter[:type], :reset, "] ",
|
82
|
+
:description, parameter[:details]
|
83
|
+
)
|
72
84
|
end
|
73
85
|
end
|
86
|
+
|
87
|
+
return printed
|
74
88
|
end
|
75
89
|
|
76
90
|
def call
|
@@ -79,23 +93,30 @@ module Bake
|
|
79
93
|
context = @parent.context
|
80
94
|
|
81
95
|
if scope = context.scope
|
82
|
-
terminal
|
83
|
-
|
84
|
-
|
96
|
+
printed = print_scope(terminal, context.scope) do
|
97
|
+
terminal.print_line(:context, context)
|
98
|
+
end
|
85
99
|
|
86
|
-
|
100
|
+
if printed
|
101
|
+
terminal.print_line
|
102
|
+
end
|
87
103
|
end
|
88
104
|
|
89
105
|
context.loaders.each do |loader|
|
90
|
-
|
106
|
+
printed = false
|
91
107
|
|
92
108
|
loader.each do |path|
|
93
109
|
if scope = loader.scope_for(path)
|
94
|
-
print_scope(terminal, scope)
|
110
|
+
print_scope(terminal, scope, printed: printed) do
|
111
|
+
terminal.print_line(:loader, loader)
|
112
|
+
printed = true
|
113
|
+
end
|
95
114
|
end
|
96
115
|
end
|
97
116
|
|
98
|
-
|
117
|
+
if printed
|
118
|
+
terminal.print_line
|
119
|
+
end
|
99
120
|
end
|
100
121
|
end
|
101
122
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'scope'
|
22
|
+
|
23
|
+
module Bake
|
24
|
+
class Documentation
|
25
|
+
|
26
|
+
def initialize(comments)
|
27
|
+
@comments = comments
|
28
|
+
end
|
29
|
+
|
30
|
+
DESCRIPTION = /\A\s*([^@\s].*)?\z/
|
31
|
+
|
32
|
+
def description
|
33
|
+
return to_enum(:description) unless block_given?
|
34
|
+
|
35
|
+
# We track empty lines and only yield a single empty line when there is another line of text:
|
36
|
+
gap = false
|
37
|
+
|
38
|
+
@comments.each do |comment|
|
39
|
+
if match = comment.match(DESCRIPTION)
|
40
|
+
if match[1]
|
41
|
+
if gap
|
42
|
+
yield ""
|
43
|
+
gap = false
|
44
|
+
end
|
45
|
+
|
46
|
+
yield match[1]
|
47
|
+
else
|
48
|
+
gap = true
|
49
|
+
end
|
50
|
+
else
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
ATTRIBUTE = /\A\s*@(?<name>.*?)\s+(?<value>.*?)\z/
|
57
|
+
|
58
|
+
def attributes
|
59
|
+
return to_enum(:attributes) unless block_given?
|
60
|
+
|
61
|
+
@comments.each do |comment|
|
62
|
+
if match = comment.match(ATTRIBUTE)
|
63
|
+
yield match
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
PARAMETER = /\A\s*@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\z/
|
69
|
+
|
70
|
+
def parameters
|
71
|
+
return to_enum(:parameters) unless block_given?
|
72
|
+
|
73
|
+
@comments.each do |comment|
|
74
|
+
if match = comment.match(PARAMETER)
|
75
|
+
yield match
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/bake/recipe.rb
CHANGED
@@ -19,17 +19,17 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'types'
|
22
|
+
require_relative 'documentation'
|
22
23
|
|
23
24
|
module Bake
|
24
|
-
PARAMETER = /@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\Z/
|
25
|
-
|
26
25
|
class Recipe
|
27
26
|
def initialize(instance, name, method = nil)
|
28
27
|
@instance = instance
|
29
28
|
@name = name
|
30
29
|
@command = nil
|
31
|
-
@
|
30
|
+
@comments = nil
|
32
31
|
@types = nil
|
32
|
+
@documentation = nil
|
33
33
|
|
34
34
|
@method = method
|
35
35
|
@arity = nil
|
@@ -136,8 +136,12 @@ module Bake
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
def
|
140
|
-
@
|
139
|
+
def comments
|
140
|
+
@comments ||= read_comments
|
141
|
+
end
|
142
|
+
|
143
|
+
def documentation
|
144
|
+
@documentation ||= Documentation.new(self.comments)
|
141
145
|
end
|
142
146
|
|
143
147
|
def types
|
@@ -158,23 +162,21 @@ module Bake
|
|
158
162
|
end
|
159
163
|
end
|
160
164
|
|
161
|
-
|
165
|
+
COMMENT = /\A\s*\#\s?(.*?)\Z/
|
166
|
+
|
167
|
+
def read_comments
|
162
168
|
file, line_number = self.method.source_location
|
163
169
|
|
164
170
|
lines = File.readlines(file)
|
165
171
|
line_index = line_number - 1
|
166
172
|
|
167
|
-
# Legacy "recipe" syntax:
|
168
|
-
if match = lines[line_index].match(/description: "(.*?)"/)
|
169
|
-
return [match[1]]
|
170
|
-
end
|
171
|
-
|
172
173
|
description = []
|
173
174
|
line_index -= 1
|
174
175
|
|
175
176
|
# Extract comment preceeding method:
|
176
177
|
while line = lines[line_index]
|
177
|
-
|
178
|
+
# \Z matches a trailing newline:
|
179
|
+
if match = line.match(COMMENT)
|
178
180
|
description.unshift(match[1])
|
179
181
|
else
|
180
182
|
break
|
@@ -189,10 +191,8 @@ module Bake
|
|
189
191
|
def read_types
|
190
192
|
types = {}
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
-
types[fields[:name].to_sym] = Types.parse(fields[:type])
|
195
|
-
end
|
194
|
+
self.documentation.parameters do |parameter|
|
195
|
+
types[parameter[:name].to_sym] = Types.parse(parameter[:type])
|
196
196
|
end
|
197
197
|
|
198
198
|
return types
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'any'
|
22
|
+
|
23
|
+
module Bake
|
24
|
+
module Types
|
25
|
+
module Input
|
26
|
+
extend Type
|
27
|
+
|
28
|
+
def self.composite?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.parse(input)
|
33
|
+
case input
|
34
|
+
when '-'
|
35
|
+
return $stdin
|
36
|
+
else
|
37
|
+
File.open(input)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'any'
|
22
|
+
|
23
|
+
module Bake
|
24
|
+
module Types
|
25
|
+
module Output
|
26
|
+
extend Type
|
27
|
+
|
28
|
+
def self.composite?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.parse(input)
|
33
|
+
case input
|
34
|
+
when '-'
|
35
|
+
return $stdout
|
36
|
+
else
|
37
|
+
File.open(input, "w")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/bake/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: samovar
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/bake/command/list.rb
|
119
119
|
- lib/bake/command/top.rb
|
120
120
|
- lib/bake/context.rb
|
121
|
+
- lib/bake/documentation.rb
|
121
122
|
- lib/bake/loader.rb
|
122
123
|
- lib/bake/loaders.rb
|
123
124
|
- lib/bake/recipe.rb
|
@@ -129,8 +130,10 @@ files:
|
|
129
130
|
- lib/bake/types/decimal.rb
|
130
131
|
- lib/bake/types/float.rb
|
131
132
|
- lib/bake/types/hash.rb
|
133
|
+
- lib/bake/types/input.rb
|
132
134
|
- lib/bake/types/integer.rb
|
133
135
|
- lib/bake/types/nil.rb
|
136
|
+
- lib/bake/types/output.rb
|
134
137
|
- lib/bake/types/string.rb
|
135
138
|
- lib/bake/types/symbol.rb
|
136
139
|
- lib/bake/types/tuple.rb
|