bake 0.3.0 → 0.4.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/lib/bake/command/call.rb +0 -18
- data/lib/bake/command/list.rb +15 -5
- data/lib/bake/command/top.rb +5 -35
- data/lib/bake/context.rb +56 -28
- data/lib/bake/recipe.rb +14 -9
- data/lib/bake/scope.rb +2 -0
- data/lib/bake/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 190cf7469e9cbb8f4db68447334aa9797050e06da5b351755b6d8580e70a8b71
|
4
|
+
data.tar.gz: b0ccbec0d89acf14fdd81a503736d0a66242deb4a18f07601c2bcf92fb25c4a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78493f41f9267d11ff32e5280fff448fdd0541f6527d2cf59059f2650ca60c3e1436f40388721c2e9d3263b8ada72b5f2b49fd30cc36853723208c7c93e88506
|
7
|
+
data.tar.gz: d922e66e49de98e5c01f5504f42e80064e435ffe9f357b4d900a8dbe6d4d942be9dc2d661b0a8d5c54e84ef73e42288aaf3fce4843916b11aef2fd4dd1344dfc
|
data/lib/bake/command/call.rb
CHANGED
@@ -33,29 +33,11 @@ module Bake
|
|
33
33
|
@parent.bakefile
|
34
34
|
end
|
35
35
|
|
36
|
-
def update_working_directory
|
37
|
-
if bakefile = self.bakefile
|
38
|
-
current_directory = Dir.pwd
|
39
|
-
working_directory = File.dirname(bakefile)
|
40
|
-
|
41
|
-
if working_directory != current_directory
|
42
|
-
Console.logger.debug(self) {"Changing working directory to #{working_directory.inspect}."}
|
43
|
-
Dir.chdir(working_directory)
|
44
|
-
|
45
|
-
return current_directory
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
return nil
|
50
|
-
end
|
51
|
-
|
52
36
|
many :commands, "The commands & arguments to invoke.", default: ["default"]
|
53
37
|
|
54
38
|
def call
|
55
39
|
context = @parent.context
|
56
40
|
|
57
|
-
self.update_working_directory
|
58
|
-
|
59
41
|
context.call(*@commands)
|
60
42
|
end
|
61
43
|
end
|
data/lib/bake/command/list.rb
CHANGED
@@ -24,6 +24,8 @@ require 'set'
|
|
24
24
|
module Bake
|
25
25
|
module Command
|
26
26
|
class List < Samovar::Command
|
27
|
+
PARAMETER = /@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\Z/
|
28
|
+
|
27
29
|
def format_parameters(parameters, terminal)
|
28
30
|
parameters.each do |type, name|
|
29
31
|
case type
|
@@ -53,16 +55,22 @@ module Bake
|
|
53
55
|
def print_scope(terminal, scope)
|
54
56
|
format_recipe = self.method(:format_recipe).curry
|
55
57
|
|
56
|
-
scope.recipes do |recipe|
|
58
|
+
scope.recipes.sort_by(&:command).each do |recipe|
|
57
59
|
terminal.print_line
|
58
60
|
terminal.print_line("\t", format_recipe[recipe])
|
59
61
|
|
60
62
|
recipe.description.each do |line|
|
61
|
-
|
63
|
+
if match = line.match(PARAMETER)
|
64
|
+
terminal.print_line("\t\t",
|
65
|
+
:parameter, match[:name], :reset, " [",
|
66
|
+
:type, match[:type], :reset, "] ",
|
67
|
+
:description, match[:details]
|
68
|
+
)
|
69
|
+
else
|
70
|
+
terminal.print_line("\t\t", :description, line)
|
71
|
+
end
|
62
72
|
end
|
63
73
|
end
|
64
|
-
|
65
|
-
terminal.print_line
|
66
74
|
end
|
67
75
|
|
68
76
|
def call
|
@@ -70,7 +78,9 @@ module Bake
|
|
70
78
|
terminal = @parent.terminal
|
71
79
|
context = @parent.context
|
72
80
|
|
73
|
-
|
81
|
+
if scope = context.scope
|
82
|
+
print_scope(terminal, context.scope)
|
83
|
+
end
|
74
84
|
|
75
85
|
context.loaders.each do |loader|
|
76
86
|
terminal.print_line(:loader, loader)
|
data/lib/bake/command/top.rb
CHANGED
@@ -29,27 +29,9 @@ module Bake
|
|
29
29
|
class Top < Samovar::Command
|
30
30
|
self.description = "Execute tasks using Ruby."
|
31
31
|
|
32
|
-
def self.bakefile_path(current = Dir.pwd)
|
33
|
-
while current
|
34
|
-
bakefile_path = File.join(current, "bake.rb")
|
35
|
-
|
36
|
-
if File.exist?(bakefile_path)
|
37
|
-
return bakefile_path
|
38
|
-
end
|
39
|
-
|
40
|
-
parent = File.dirname(current)
|
41
|
-
|
42
|
-
if current == parent
|
43
|
-
break
|
44
|
-
else
|
45
|
-
current = parent
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
32
|
options do
|
51
33
|
option '-h/--help', 'Show help.'
|
52
|
-
option '-b/--bakefile <path>', '
|
34
|
+
option '-b/--bakefile <path>', 'Override the path to the bakefile to use.'
|
53
35
|
end
|
54
36
|
|
55
37
|
nested :command, {
|
@@ -69,29 +51,17 @@ module Bake
|
|
69
51
|
terminal[:keyreq] = terminal.style(:red, nil, :bold)
|
70
52
|
terminal[:keyrest] = terminal.style(:green)
|
71
53
|
|
54
|
+
terminal[:parameter] = terminal[:opt]
|
55
|
+
|
72
56
|
return terminal
|
73
57
|
end
|
74
58
|
|
75
59
|
def bakefile
|
76
|
-
@options[:bakefile]
|
77
|
-
end
|
78
|
-
|
79
|
-
def working_directory
|
80
|
-
if bakefile = self.bakefile
|
81
|
-
File.dirname(self.bakefile)
|
82
|
-
else
|
83
|
-
Dir.pwd
|
84
|
-
end
|
60
|
+
@options[:bakefile] || Dir.pwd
|
85
61
|
end
|
86
62
|
|
87
63
|
def context
|
88
|
-
|
89
|
-
return Context.load(self.bakefile)
|
90
|
-
else
|
91
|
-
raise "Cannot find `bake.rb` file."
|
92
|
-
end
|
93
|
-
|
94
|
-
return context
|
64
|
+
Context.load(self.bakefile)
|
95
65
|
end
|
96
66
|
|
97
67
|
def call
|
data/lib/bake/context.rb
CHANGED
@@ -21,36 +21,71 @@
|
|
21
21
|
require_relative 'base'
|
22
22
|
|
23
23
|
module Bake
|
24
|
+
BAKEFILE = "bake.rb"
|
25
|
+
|
24
26
|
class Context
|
25
|
-
|
26
|
-
|
27
|
+
# If path points to a file, assume it's a `bake.rb` file. Otherwise, recursively search up the directory tree starting from `path` to find the specified bakefile.
|
28
|
+
# @return [String, nil] the path to the bakefile if it could be found.
|
29
|
+
def self.bakefile_path(path, bakefile: BAKEFILE)
|
30
|
+
if File.file?(path)
|
31
|
+
return path
|
32
|
+
end
|
33
|
+
|
34
|
+
current = path
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
36
|
+
while current
|
37
|
+
bakefile_path = File.join(current, BAKEFILE)
|
38
|
+
|
39
|
+
if File.exist?(bakefile_path)
|
40
|
+
return bakefile_path
|
41
|
+
end
|
42
|
+
|
43
|
+
parent = File.dirname(current)
|
44
|
+
|
45
|
+
if current == parent
|
46
|
+
break
|
31
47
|
else
|
32
|
-
|
33
|
-
loaders = Loaders.default(working_directory)
|
48
|
+
current = parent
|
34
49
|
end
|
35
50
|
end
|
36
51
|
|
37
|
-
|
52
|
+
return nil
|
38
53
|
end
|
39
54
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
55
|
+
def self.load(path)
|
56
|
+
if bakefile_path = self.bakefile_path(path)
|
57
|
+
scope = Scope.load(bakefile_path)
|
58
|
+
|
59
|
+
working_directory = File.dirname(bakefile_path)
|
60
|
+
loaders = Loaders.default(working_directory)
|
61
|
+
else
|
62
|
+
scope = nil
|
63
|
+
|
64
|
+
working_directory = path
|
65
|
+
loaders = Loaders.default(working_directory)
|
66
|
+
end
|
43
67
|
|
68
|
+
return self.new(loaders, scope, working_directory)
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize(loaders, scope = nil, root = nil)
|
44
72
|
@loaders = loaders
|
45
73
|
|
46
74
|
@stack = []
|
47
75
|
|
48
|
-
@
|
49
|
-
hash[key] =
|
76
|
+
@instances = Hash.new do |hash, key|
|
77
|
+
hash[key] = instance_for(key)
|
50
78
|
end
|
51
79
|
|
52
|
-
@scope =
|
53
|
-
@
|
80
|
+
@scope = scope
|
81
|
+
@root = root
|
82
|
+
|
83
|
+
if @scope
|
84
|
+
base = Base.derive
|
85
|
+
base.prepend(@scope)
|
86
|
+
|
87
|
+
@instances[[]] = base.new(self)
|
88
|
+
end
|
54
89
|
|
55
90
|
@recipes = Hash.new do |hash, key|
|
56
91
|
hash[key] = recipe_for(key)
|
@@ -58,6 +93,7 @@ module Bake
|
|
58
93
|
end
|
59
94
|
|
60
95
|
attr :scope
|
96
|
+
attr :root
|
61
97
|
attr :loaders
|
62
98
|
|
63
99
|
def call(*commands)
|
@@ -80,20 +116,20 @@ module Bake
|
|
80
116
|
def recipe_for(command)
|
81
117
|
path = command.split(":")
|
82
118
|
|
83
|
-
if
|
84
|
-
return
|
119
|
+
if instance = @instances[path]
|
120
|
+
return instance.recipe_for(path.last)
|
85
121
|
else
|
86
122
|
*path, name = *path
|
87
123
|
|
88
|
-
if
|
89
|
-
return
|
124
|
+
if instance = @instances[path]
|
125
|
+
return instance.recipe_for(name)
|
90
126
|
end
|
91
127
|
end
|
92
128
|
|
93
129
|
return nil
|
94
130
|
end
|
95
131
|
|
96
|
-
def
|
132
|
+
def instance_for(path)
|
97
133
|
if base = base_for(path)
|
98
134
|
return base.new(self)
|
99
135
|
end
|
@@ -113,13 +149,5 @@ module Bake
|
|
113
149
|
|
114
150
|
return base
|
115
151
|
end
|
116
|
-
|
117
|
-
def with!(scope)
|
118
|
-
@stack << scope
|
119
|
-
|
120
|
-
yield
|
121
|
-
ensure
|
122
|
-
@scope.pop
|
123
|
-
end
|
124
152
|
end
|
125
153
|
end
|
data/lib/bake/recipe.rb
CHANGED
@@ -23,6 +23,7 @@ module Bake
|
|
23
23
|
def initialize(scope, name, method = nil)
|
24
24
|
@scope = scope
|
25
25
|
@name = name
|
26
|
+
@command = nil
|
26
27
|
@description = nil
|
27
28
|
|
28
29
|
@method = method
|
@@ -52,15 +53,7 @@ module Bake
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def command
|
55
|
-
|
56
|
-
|
57
|
-
if path.empty?
|
58
|
-
@name.to_s
|
59
|
-
elsif path.last.to_sym == @name
|
60
|
-
path.join(':')
|
61
|
-
else
|
62
|
-
(path + [@name]).join(':')
|
63
|
-
end
|
56
|
+
@command ||= compute_command
|
64
57
|
end
|
65
58
|
|
66
59
|
def to_s
|
@@ -118,6 +111,18 @@ module Bake
|
|
118
111
|
|
119
112
|
private
|
120
113
|
|
114
|
+
def compute_command
|
115
|
+
path = @scope.path
|
116
|
+
|
117
|
+
if path.empty?
|
118
|
+
@name.to_s
|
119
|
+
elsif path.last.to_sym == @name
|
120
|
+
path.join(':')
|
121
|
+
else
|
122
|
+
(path + [@name]).join(':')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
121
126
|
def read_description
|
122
127
|
file, line_number = self.method.source_location
|
123
128
|
|
data/lib/bake/scope.rb
CHANGED
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.4.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-02-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: samovar
|