bake 0.13.0 → 0.15.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4138c750ccdded2e0b36d082d94fecc0ae4afd0cfda6bad6e47179e37450f47
4
- data.tar.gz: 236deaa42f0a148e195abdbeca1a8298e252ee335ea5cbceddc97e5c06dce195
3
+ metadata.gz: ffd01780c83a112850dedabde8133221e458f7ac4b654c503af3fc377537589a
4
+ data.tar.gz: 620d8e1bc09cec0d48866e8178ec015646dbe65c67c601d74b48b3d02b23e730
5
5
  SHA512:
6
- metadata.gz: 0b249b795b9f91489d0150a5d511d3d22a6d4d2292fba3f2680455a2831c9b3480abed70d107127bf45cf76d5197395b9c9be597902800c39ca95be6e761ade8
7
- data.tar.gz: ec9e06a913c3f457b227d077ae7d2e0f19d90ac7a417edcb3f1d721c0d6176dd62a178d5b6e2db5ff66084e60fda446af5c9f0ee013da98435fc15287e2f0726
6
+ metadata.gz: 320b0eac992381b168a68a4e13b8a9da69b1d13bcbc6c0f216a0eeaf47f9cca1cba99aa2454a6dd39f2d01b0ea4ebea76d7b5dce1317a06e443993cff8807d07
7
+ data.tar.gz: 2ff3baa57d105fe4ad0b81d01168be1efa1895c67bb41d6bbcf7c8681d0b2a328e36f87ce4197b203e0cf5ea81af24a785e12096692eccd7de65618a15d72faa
@@ -0,0 +1,120 @@
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 'types'
22
+ require_relative 'documentation'
23
+
24
+ module Bake
25
+ # Structured access to arguments.
26
+ class Arguments
27
+ def self.extract(recipe, arguments)
28
+ self.new(recipe).extract(arguments)
29
+ end
30
+
31
+ def initialize(recipe)
32
+ @recipe = recipe
33
+
34
+ @types = recipe.types
35
+ @parameters = recipe.parameters
36
+ @arity = recipe.arity
37
+
38
+ @ordered = []
39
+ @options = {}
40
+ end
41
+
42
+ attr :ordered
43
+ attr :options
44
+
45
+ def extract(arguments)
46
+ while argument = arguments.first
47
+ if /^--(?<name>.*)$/ =~ argument
48
+ # Consume the argument:
49
+ arguments.shift
50
+
51
+ if name.empty?
52
+ break
53
+ end
54
+
55
+ name = name.to_sym
56
+
57
+ # Extract the trailing arguments:
58
+ @options[name] = extract_arguments(name, arguments)
59
+ elsif /^(?<name>.*?)=(?<value>.*)$/ =~ argument
60
+ # Consume the argument:
61
+ arguments.shift
62
+
63
+ name = name.to_sym
64
+
65
+ # Extract the single argument:
66
+ @options[name] = extract_argument(name, value)
67
+ elsif @ordered.size < @arity
68
+ _, name = @parameters.shift
69
+ value = arguments.shift
70
+
71
+ # Consume it:
72
+ @ordered << extract_argument(name, value)
73
+ else
74
+ break
75
+ end
76
+ end
77
+
78
+ return @ordered, @options
79
+ end
80
+
81
+ private
82
+
83
+ def delimiter_index(arguments)
84
+ arguments.index{|argument| argument =~ /\A(--|;\z)/}
85
+ end
86
+
87
+ def extract_arguments(name, arguments)
88
+ value = nil
89
+ type = @types[name]
90
+
91
+ # Can this named parameter accept more than one input argument?
92
+ if type&.composite?
93
+ if count = delimiter_index(arguments)
94
+ value = arguments.shift(count)
95
+ arguments.shift if arguments.first == ';'
96
+ else
97
+ value = arguments.dup
98
+ arguments.clear
99
+ end
100
+ else
101
+ # Otherwise we just take one item:
102
+ value = arguments.shift
103
+ end
104
+
105
+ if type
106
+ value = type.parse(value)
107
+ end
108
+
109
+ return value
110
+ end
111
+
112
+ def extract_argument(name, value)
113
+ if type = @types[name]
114
+ value = type.parse(value)
115
+ end
116
+
117
+ return value
118
+ end
119
+ end
120
+ end
data/lib/bake/base.rb CHANGED
@@ -25,7 +25,7 @@ module Bake
25
25
  # The base class for including {Scope} instances which define {Recipe} instances.
26
26
  class Base < Struct.new(:context)
27
27
  # Generate a base class for the specified path.
28
- # @param path [Array(String)] The command path.
28
+ # @parameter path [Array(String)] The command path.
29
29
  def self.derive(path = [])
30
30
  klass = Class.new(self)
31
31
 
@@ -35,7 +35,7 @@ module Bake
35
35
  end
36
36
 
37
37
  # Format the class as a command.
38
- # @return [String]
38
+ # @returns [String]
39
39
  def self.to_s
40
40
  if path = self.path
41
41
  path.join(':')
@@ -53,7 +53,7 @@ module Bake
53
53
  end
54
54
 
55
55
  # The path of this derived base class.
56
- # @return [Array(String)]
56
+ # @returns [Array(String)]
57
57
  def self.path
58
58
  self.const_get(:PATH)
59
59
  rescue
@@ -61,22 +61,22 @@ module Bake
61
61
  end
62
62
 
63
63
  # The path for this derived base class.
64
- # @return [Array(String)]
64
+ # @returns [Array(String)]
65
65
  def path
66
66
  self.class.path
67
67
  end
68
68
 
69
69
  # Proxy a method call using command line arguments through to the {Context} instance.
70
- # @param arguments [Array(String)]
70
+ # @parameter arguments [Array(String)]
71
71
  def call(*arguments)
72
72
  self.context.call(*arguments)
73
73
  end
74
74
 
75
75
  # Recipes defined in this scope.
76
76
  #
77
- # @block `{|recipe| ...}`
78
- # @yield recipe [Recipe]
79
- # @return [Enumerable]
77
+ # @yields {|recipe| ...}
78
+ # @parameter recipe [Recipe]
79
+ # @returns [Enumerable]
80
80
  def recipes
81
81
  return to_enum(:recipes) unless block_given?
82
82
 
@@ -89,7 +89,7 @@ module Bake
89
89
 
90
90
  # Look up a recipe with a specific name.
91
91
  #
92
- # @param name [String] The instance method to look up.
92
+ # @parameter name [String] The instance method to look up.
93
93
  def recipe_for(name)
94
94
  Recipe.new(self, name)
95
95
  end
@@ -34,7 +34,7 @@ module Bake
34
34
  @parent.bakefile
35
35
  end
36
36
 
37
- many :commands, "The commands & arguments to invoke.", default: ["default"]
37
+ many :commands, "The commands & arguments to invoke.", default: ["default"], stop: false
38
38
 
39
39
  def call
40
40
  context = @parent.context
data/lib/bake/context.rb CHANGED
@@ -28,7 +28,7 @@ module Bake
28
28
  class Context
29
29
  # Search upwards from the specified path for a {BAKEFILE}.
30
30
  # 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.
31
- # @return [String | Nil] The path to the bakefile if it could be found.
31
+ # @returns [String | Nil] The path to the bakefile if it could be found.
32
32
  def self.bakefile_path(path, bakefile: BAKEFILE)
33
33
  if File.file?(path)
34
34
  return path
@@ -74,7 +74,7 @@ module Bake
74
74
  end
75
75
 
76
76
  # Initialize the context with the specified loaders.
77
- # @param loaders [Loaders]
77
+ # @parameter loaders [Loaders]
78
78
  def initialize(loaders, scope = nil, root = nil)
79
79
  @loaders = loaders
80
80
 
@@ -106,11 +106,11 @@ module Bake
106
106
  attr :scope
107
107
 
108
108
  # The root path of this context.
109
- # @return [String | Nil]
109
+ # @returns [String | Nil]
110
110
  attr :root
111
111
 
112
112
  # Invoke recipes on the context using command line arguments.
113
- # @param commands [Array(String)]
113
+ # @parameter commands [Array(String)]
114
114
  def call(*commands)
115
115
  last_result = nil
116
116
 
@@ -127,7 +127,7 @@ module Bake
127
127
  end
128
128
 
129
129
  # Lookup a recipe for the given command name.
130
- # @param command [String] The command name, e.g. `bundler:release`.
130
+ # @parameter command [String] The command name, e.g. `bundler:release`.
131
131
  def lookup(command)
132
132
  @recipes[command]
133
133
  end
@@ -140,6 +140,10 @@ module Bake
140
140
  end
141
141
  end
142
142
 
143
+ def inspect
144
+ "\#<#{self.class} #{@root}>"
145
+ end
146
+
143
147
  private
144
148
 
145
149
  def recipe_for(command)
@@ -164,7 +168,7 @@ module Bake
164
168
  end
165
169
  end
166
170
 
167
- # @param path [Array<String>] the path for the scope.
171
+ # @parameter path [Array<String>] the path for the scope.
168
172
  def base_for(path)
169
173
  base = nil
170
174
 
@@ -25,7 +25,7 @@ module Bake
25
25
  class Documentation
26
26
  # Initialize the documentation with an array of comments.
27
27
  #
28
- # @param comments [Array(String)] An array of comment lines.
28
+ # @parameter comments [Array(String)] An array of comment lines.
29
29
  def initialize(comments)
30
30
  @comments = comments
31
31
  end
@@ -34,8 +34,9 @@ module Bake
34
34
 
35
35
  # The text-only lines of the comment block.
36
36
  #
37
- # @yield [String]
38
- # @return [Enumerable]
37
+ # @yields {|match| ...}
38
+ # @parameter match [MatchData] The regular expression match for each line of documentation.
39
+ # @returns [Enumerable] If no block given.
39
40
  def description
40
41
  return to_enum(:description) unless block_given?
41
42
 
@@ -63,10 +64,11 @@ module Bake
63
64
  ATTRIBUTE = /\A\s*@(?<name>.*?)\s+(?<value>.*?)\z/
64
65
 
65
66
  # The attribute lines of the comment block.
66
- # e.g. `@return [String]`.
67
+ # e.g. `@returns [String]`.
67
68
  #
68
- # @yield [String]
69
- # @return [Enumerable]
69
+ # @yields {|match| ...}
70
+ # @parameter match [MatchData] The regular expression match with `name` and `value` keys.
71
+ # @returns [Enumerable] If no block given.
70
72
  def attributes
71
73
  return to_enum(:attributes) unless block_given?
72
74
 
@@ -77,13 +79,14 @@ module Bake
77
79
  end
78
80
  end
79
81
 
80
- PARAMETER = /\A\s*@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\z/
82
+ PARAMETER = /\A\s*@param(eter)?\s+(?<name>.*?)\s+\[(?<type>.*?)\](\s+(?<details>.*?))?\z/
81
83
 
82
84
  # The parameter lines of the comment block.
83
- # e.g. `@param value [String] The value.`
85
+ # e.g. `@parameter value [String] The value.`
84
86
  #
85
- # @yield [String]
86
- # @return [Enumerable]
87
+ # @yields {|match| ...}
88
+ # @parameter match [MatchData] The regular expression match with `name`, `type` and `details` keys.
89
+ # @returns [Enumerable] If no block given.
87
90
  def parameters
88
91
  return to_enum(:parameters) unless block_given?
89
92
 
data/lib/bake/loader.rb CHANGED
@@ -24,7 +24,7 @@ module Bake
24
24
  # Represents a directory which contains bakefiles.
25
25
  class Loader
26
26
  # Initialize the loader with the specified root path.
27
- # @param root [String] A file-system path.
27
+ # @parameter root [String] A file-system path.
28
28
  def initialize(root, name: nil)
29
29
  @root = root
30
30
  @name = name
@@ -38,8 +38,8 @@ module Bake
38
38
  attr :root
39
39
 
40
40
  # Enumerate all bakefiles within the loaders root directory.
41
- # @block `{|path| ...}`
42
- # @yield path [String] The Ruby source file path.
41
+ # @yields {|path| ...}
42
+ # @parameter path [String] The Ruby source file path.
43
43
  def each
44
44
  return to_enum unless block_given?
45
45
 
@@ -49,7 +49,7 @@ module Bake
49
49
  end
50
50
 
51
51
  # Load the {Scope} for the specified relative path within this loader, if it exists.
52
- # @param path [Array(String)] A relative path.
52
+ # @parameter path [Array(String)] A relative path.
53
53
  def scope_for(path)
54
54
  *directory, file = *path
55
55
 
data/lib/bake/loaders.rb CHANGED
@@ -28,7 +28,7 @@ module Bake
28
28
  include Enumerable
29
29
 
30
30
  # Create a loader using the specified working directory.
31
- # @param working_directory [String]
31
+ # @parameter working_directory [String]
32
32
  def self.default(working_directory)
33
33
  loaders = self.new
34
34
 
@@ -44,13 +44,13 @@ module Bake
44
44
  end
45
45
 
46
46
  # Whether any loaders are defined.
47
- # @return [Boolean]
47
+ # @returns [Boolean]
48
48
  def empty?
49
49
  @ordered.empty?
50
50
  end
51
51
 
52
52
  # Add loaders according to the current working directory and loaded gems.
53
- # @param working_directory [String]
53
+ # @parameter working_directory [String]
54
54
  def append_defaults(working_directory)
55
55
  # Load recipes from working directory:
56
56
  self.append_path(working_directory)
@@ -66,7 +66,7 @@ module Bake
66
66
 
67
67
  # Append a specific project path to the search path for recipes.
68
68
  # The computed path will have `bake` appended to it.
69
- # @param current [String] The path to add.
69
+ # @parameter current [String] The path to add.
70
70
  def append_path(current = Dir.pwd, **options)
71
71
  bake_path = File.join(current, "bake")
72
72
 
@@ -78,7 +78,7 @@ module Bake
78
78
  end
79
79
 
80
80
  # Search from the current working directory until a suitable bakefile is found and add it.
81
- # @param current [String] The path to start searching from.
81
+ # @parameter current [String] The path to start searching from.
82
82
  def append_from_root(current = Dir.pwd, **options)
83
83
  while current
84
84
  append_path(current, **options)
data/lib/bake/recipe.rb CHANGED
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'types'
22
+ require_relative 'arguments'
22
23
  require_relative 'documentation'
23
24
 
24
25
  module Bake
@@ -26,9 +27,9 @@ module Bake
26
27
  class Recipe
27
28
  # Initialize the recipe.
28
29
  #
29
- # @param instance [Base] The instance this recipe is attached to.
30
- # @param name [String] The method name.
31
- # @param method [Method | Nil] The method if already known.
30
+ # @parameter instance [Base] The instance this recipe is attached to.
31
+ # @parameter name [String] The method name.
32
+ # @parameter method [Method | Nil] The method if already known.
32
33
  def initialize(instance, name, method = nil)
33
34
  @instance = instance
34
35
  @name = name
@@ -63,7 +64,7 @@ module Bake
63
64
  end
64
65
 
65
66
  # The recipe's formal parameters, if any.
66
- # @return [Array | Nil]
67
+ # @returns [Array | Nil]
67
68
  def parameters
68
69
  parameters = method.parameters
69
70
 
@@ -73,7 +74,7 @@ module Bake
73
74
  end
74
75
 
75
76
  # Whether this recipe has optional arguments.
76
- # @return [Boolean]
77
+ # @returns [Boolean]
77
78
  def options?
78
79
  if parameters = self.parameters
79
80
  type, name = parameters.last
@@ -101,44 +102,11 @@ module Bake
101
102
  end
102
103
 
103
104
  # Process command line arguments into the ordered and optional arguments.
104
- # @param arguments [Array(String)] The command line arguments
105
- # @return ordered [Array]
106
- # @return options [Hash]
105
+ # @parameter arguments [Array(String)] The command line arguments
106
+ # @returns ordered [Array]
107
+ # @returns options [Hash]
107
108
  def prepare(arguments)
108
- offset = 0
109
- ordered = []
110
- options = {}
111
- parameters = method.parameters.dup
112
- types = self.types
113
-
114
- while argument = arguments.first
115
- name, value = argument.split('=', 2)
116
-
117
- if name and value
118
- # Consume it:
119
- arguments.shift
120
-
121
- if type = types[name.to_sym]
122
- value = type.parse(value)
123
- end
124
-
125
- options[name.to_sym] = value
126
- elsif ordered.size < self.arity
127
- _, name = parameters.shift
128
- value = arguments.shift
129
-
130
- if type = types[name]
131
- value = type.parse(value)
132
- end
133
-
134
- # Consume it:
135
- ordered << value
136
- else
137
- break
138
- end
139
- end
140
-
141
- return ordered, options
109
+ Arguments.extract(self, arguments)
142
110
  end
143
111
 
144
112
  # Call the recipe with the specified arguments and options.
@@ -152,25 +120,38 @@ module Bake
152
120
  end
153
121
 
154
122
  # Any comments associated with the source code which defined the method.
155
- # @return [Array(String)] The comment lines.
123
+ # @returns [Array(String)] The comment lines.
156
124
  def comments
157
125
  @comments ||= read_comments
158
126
  end
159
127
 
160
128
  # The documentation object which provides structured access to the {comments}.
161
- # @return [Documentation]
129
+ # @returns [Documentation]
162
130
  def documentation
163
131
  @documentation ||= Documentation.new(self.comments)
164
132
  end
165
133
 
166
134
  # The documented type signature of the recipe.
167
- # @return [Array] An array of {Types} instances.
135
+ # @returns [Array] An array of {Types} instances.
168
136
  def types
169
137
  @types ||= read_types
170
138
  end
171
139
 
172
140
  private
173
141
 
142
+ def parse(name, value, arguments, types)
143
+ if count = arguments.index(';')
144
+ value = arguments.shift(count)
145
+ arguments.shift
146
+ end
147
+
148
+ if type = types[name]
149
+ value = type.parse(value)
150
+ end
151
+
152
+ return value
153
+ end
154
+
174
155
  def compute_command
175
156
  path = @instance.path
176
157
 
data/lib/bake/scope.rb CHANGED
@@ -42,9 +42,9 @@ module Bake
42
42
 
43
43
  # Recipes defined in this scope.
44
44
  #
45
- # @block `{|recipe| ...}`
46
- # @yield recipe [Recipe]
47
- # @return [Enumerable]
45
+ # @yields {|recipe| ...}
46
+ # @parameter recipe [Recipe]
47
+ # @returns [Enumerable]
48
48
  def recipes
49
49
  return to_enum(:recipes) unless block_given?
50
50
 
@@ -62,7 +62,7 @@ module Bake
62
62
 
63
63
  # Look up a recipe with a specific name.
64
64
  #
65
- # @param name [String] The instance method to look up.
65
+ # @parameter name [String] The instance method to look up.
66
66
  def recipe_for(name)
67
67
  Recipe.new(self, name, self.instance_method(name))
68
68
  end
@@ -28,25 +28,25 @@ module Bake
28
28
  #
29
29
  class Any
30
30
  # Initialize the instance with an array of types.
31
- # @param types [Array] the array of types.
31
+ # @parameter types [Array] the array of types.
32
32
  def initialize(types)
33
33
  @types = types
34
34
  end
35
35
 
36
36
  # Create a copy of the current instance with the other type appended.
37
- # @param other [Type] the type instance to append.
37
+ # @parameter other [Type] the type instance to append.
38
38
  def | other
39
39
  self.class.new([*@types, other])
40
40
  end
41
41
 
42
42
  # Whether any of the listed types is a composite type.
43
- # @return [Boolean] true if any of the listed types is `composite?`.
43
+ # @returns [Boolean] true if any of the listed types is `composite?`.
44
44
  def composite?
45
45
  @types.any?{|type| type.composite?}
46
46
  end
47
47
 
48
48
  # Parse an input string, trying the listed types in order, returning the first one which doesn't raise an exception.
49
- # @param input [String] the input to parse, e.g. `"5"`.
49
+ # @parameter input [String] the input to parse, e.g. `"5"`.
50
50
  def parse(input)
51
51
  @types.each do |type|
52
52
  return type.parse(input)
@@ -69,7 +69,7 @@ module Bake
69
69
  # An extension module which allows constructing `Any` types using the `|` operator.
70
70
  module Type
71
71
  # Create an instance of `Any` with the arguments as types.
72
- # @param other [Type] the alternative type to match.
72
+ # @parameter other [Type] the alternative type to match.
73
73
  def | other
74
74
  Any.new([self, other])
75
75
  end
@@ -33,8 +33,19 @@ module Bake
33
33
  true
34
34
  end
35
35
 
36
+ def map(values)
37
+ values.map{|value| @item_type.parse(value)}
38
+ end
39
+
36
40
  def parse(input)
37
- input.split(',').map{|value| @item_type.parse(value)}
41
+ case input
42
+ when ::String
43
+ return input.split(',').map{|value| @item_type.parse(value)}
44
+ when ::Array
45
+ return input.map{|value| @item_type.parse(value)}
46
+ else
47
+ raise ArgumentError, "Cannot coerce #{input.inspect} into array!"
48
+ end
38
49
  end
39
50
 
40
51
  def to_s
@@ -32,6 +32,10 @@ module Bake
32
32
  def self.parse(input)
33
33
  if input =~ /t(rue)?|y(es)?/i
34
34
  return true
35
+ elsif input =~ /f(alse)?|n(o)?/i
36
+ return false
37
+ else
38
+ raise ArgumentError, "Cannot coerce #{input.inspect} into boolean!"
35
39
  end
36
40
  end
37
41
  end
@@ -33,7 +33,7 @@ module Bake
33
33
  if input =~ /nil|null/i
34
34
  return nil
35
35
  else
36
- raise ArgumentError, "Cannot coerce #{input} into nil!"
36
+ raise ArgumentError, "Cannot coerce #{input.inspect} into nil!"
37
37
  end
38
38
  end
39
39
  end
@@ -34,7 +34,14 @@ module Bake
34
34
  end
35
35
 
36
36
  def parse(input)
37
- input.split(',').map{|value| @item_type.parse(value)}
37
+ case input
38
+ when ::String
39
+ return input.split(',').map{|value| @item_type.parse(value)}
40
+ when ::Array
41
+ return input.map{|value| @item_type.parse(value)}
42
+ else
43
+ raise ArgumentError, "Cannot coerce #{input.inspect} into tuple!"
44
+ end
38
45
  end
39
46
 
40
47
  def to_s
data/lib/bake/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Bake
22
- VERSION = "0.13.0"
22
+ VERSION = "0.15.1"
23
23
  end
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.13.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-04 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: samovar
@@ -25,21 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bake-bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: utopia-project
28
+ name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -66,20 +52,6 @@ dependencies:
66
52
  - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: bundler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: rspec
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,40 +66,16 @@ dependencies:
94
66
  - - ">="
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- description:
69
+ description:
112
70
  email:
113
- - samuel.williams@oriontransfer.co.nz
114
71
  executables:
115
72
  - bake
116
73
  extensions: []
117
74
  extra_rdoc_files: []
118
75
  files:
119
- - ".github/workflows/development.yml"
120
- - ".gitignore"
121
- - ".rspec"
122
- - README.md
123
- - bake.gemspec
124
- - bake.rb
125
76
  - bin/bake
126
- - gems.rb
127
- - guides/command-line-interface/README.md
128
- - guides/gem-integration/README.md
129
- - guides/project-integration/README.md
130
77
  - lib/bake.rb
78
+ - lib/bake/arguments.rb
131
79
  - lib/bake/base.rb
132
80
  - lib/bake/command.rb
133
81
  - lib/bake/command/call.rb
@@ -158,8 +106,8 @@ homepage: https://github.com/ioquatix/bake
158
106
  licenses:
159
107
  - MIT
160
108
  metadata:
161
- donation_uri: https://github.com/sponsors/ioquatix
162
- post_install_message:
109
+ funding_uri: https://github.com/sponsors/ioquatix/
110
+ post_install_message:
163
111
  rdoc_options: []
164
112
  require_paths:
165
113
  - lib
@@ -174,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
122
  - !ruby/object:Gem::Version
175
123
  version: '0'
176
124
  requirements: []
177
- rubygems_version: 3.1.2
178
- signing_key:
125
+ rubygems_version: 3.2.15
126
+ signing_key:
179
127
  specification_version: 4
180
128
  summary: A replacement for rake with a simpler syntax.
181
129
  test_files: []
@@ -1,35 +0,0 @@
1
- name: Development
2
-
3
- on: [push]
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- matrix:
9
- os:
10
- - ubuntu
11
- - macos
12
-
13
- ruby:
14
- - 2.5
15
- - 2.6
16
- - 2.7
17
-
18
- include:
19
- - os: 'ubuntu'
20
- ruby: '2.6'
21
- env: COVERAGE=PartialSummary,Coveralls
22
-
23
- runs-on: ${{matrix.os}}-latest
24
-
25
- steps:
26
- - uses: actions/checkout@v1
27
- - uses: actions/setup-ruby@v1
28
- with:
29
- ruby-version: ${{matrix.ruby}}
30
- - name: Install dependencies
31
- run: |
32
- command -v bundler || gem install bundler
33
- bundle install
34
- - name: Run tests
35
- run: ${{matrix.env}} bundle exec rspec
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- gems.locked
11
-
12
- # rspec failure tracking
13
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/README.md DELETED
@@ -1,64 +0,0 @@
1
- # Bake
2
-
3
- Bake is a task execution tool, inspired by Rake, but codifying many of the use cases which are typically implemented in an ad-hoc manner.
4
-
5
- [![Development](https://github.com/ioquatix/bake/workflows/Development/badge.svg)](https://github.com/ioquatix/bake/actions?workflow=Development)
6
-
7
- ## Motivation
8
-
9
- Rake is an awesome tool and loved by the community. So, why reinvent it? Bake provides the following features that Rake does not:
10
-
11
- - On demand loading of files following a standard convention. This avoid loading all your rake tasks just to execute a single command.
12
- - Better argument handling including support for positional and optional arguments.
13
- - Focused on task execution not dependency resolution. Implementation is simpler and a bit more predictable.
14
- - Canonical structure for integration with gems.
15
-
16
- That being said, Rake and Bake can exist side by side in the same project.
17
-
18
- ## Installation
19
-
20
- Execute the following in your project:
21
-
22
- bundle add bake
23
-
24
- ## Usage
25
-
26
- Please see the <a href="https://ioquatix.github.io/bake/">project documentation</a> or run it locally using `bake utopia:project:serve`.
27
-
28
- ## Contributing
29
-
30
- 1. Fork it
31
- 2. Create your feature branch (`git checkout -b my-new-feature`)
32
- 3. Commit your changes (`git commit -am 'Add some feature'`)
33
- 4. Push to the branch (`git push origin my-new-feature`)
34
- 5. Create new Pull Request
35
-
36
- ## See Also
37
-
38
- - [Console](https://github.com/socketry/console) — A logging framework which integrates with bake.
39
- - [Variant](https://github.com/socketry/variant) — A framework for selecting different environments, including bake tasks.
40
- - [Utopia](https://github.com/socketry/utopia) — A website framework which uses bake for maintenance tasks.
41
-
42
- ## License
43
-
44
- Released under the MIT license.
45
-
46
- Copyright, 2020, by [Samuel G. D. Williams](http://www.codeotaku.com).
47
-
48
- Permission is hereby granted, free of charge, to any person obtaining a copy
49
- of this software and associated documentation files (the "Software"), to deal
50
- in the Software without restriction, including without limitation the rights
51
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
- copies of the Software, and to permit persons to whom the Software is
53
- furnished to do so, subject to the following conditions:
54
-
55
- The above copyright notice and this permission notice shall be included in
56
- all copies or substantial portions of the Software.
57
-
58
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64
- THE SOFTWARE.
data/bake.gemspec DELETED
@@ -1,33 +0,0 @@
1
- require_relative 'lib/bake/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "bake"
5
- spec.version = Bake::VERSION
6
- spec.authors = ["Samuel Williams"]
7
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
8
-
9
- spec.summary = "A replacement for rake with a simpler syntax."
10
- spec.homepage = "https://github.com/ioquatix/bake"
11
- spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
13
-
14
- spec.metadata["donation_uri"] = "https://github.com/sponsors/ioquatix"
15
-
16
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(docs|test|spec|features)/}) }
18
- end
19
-
20
- spec.bindir = "bin"
21
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency 'samovar', '~> 2.1'
25
-
26
- spec.add_development_dependency 'bake-bundler'
27
-
28
- spec.add_development_dependency 'utopia-project'
29
- spec.add_development_dependency 'covered'
30
- spec.add_development_dependency 'bundler'
31
- spec.add_development_dependency 'rspec'
32
- spec.add_development_dependency 'rake'
33
- end
data/bake.rb DELETED
File without changes
data/gems.rb DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in bake.gemspec
4
- gemspec
@@ -1,55 +0,0 @@
1
- # Command Line Interface
2
-
3
- The `bake` command is broken up into two main functions: `list` and `call`.
4
-
5
- <pre>% bake --help
6
- <b>bake [-h/--help] [-b/--bakefile &lt;path&gt;] &lt;command&gt;</b>
7
- <font color="#638FFF">Execute tasks using Ruby.</font>
8
-
9
- [-h/--help] Show help.
10
- [-b/--bakefile &lt;path&gt;] Override the path to the bakefile to use.
11
- &lt;command&gt; One of: call, list. (default: call)
12
-
13
- <b>call &lt;commands...&gt;</b>
14
- <font color="#638FFF">Execute one or more commands.</font>
15
-
16
- &lt;commands...&gt; The commands &amp; arguments to invoke. (default: [&quot;default&quot;])
17
-
18
- <b>list &lt;pattern&gt;</b>
19
- &lt;pattern&gt; The pattern to filter tasks by.
20
- </pre>
21
-
22
- ## List
23
-
24
- The `bake list` command allows you to list all available recipes. By proving a pattern you will only see recipes that have a matching command name.
25
-
26
- <pre>$ bake list console
27
- <b>Bake::Loader console-1.8.2</b>
28
-
29
- <b>console:info</b>
30
- <font color="#638FFF">Increase the verbosity of the logger to info.</font>
31
-
32
- <b>console:debug</b>
33
- <font color="#638FFF">Increase the verbosity of the logger to debug.</font>
34
- </pre>
35
-
36
- The listing documents positional and optional arguments. The documentation is generated from the comments in the bakefiles.
37
-
38
- ## Call
39
-
40
- The `bake call` (the default, so `call` can be omitted) allows you to execute one or more recipes. You must provide the name of the command, followed by any arguments.
41
-
42
- <pre>$ bake async:http:head https://www.codeotaku.com/index
43
- <font color="#638FFF"><b> HEAD</b></font>: https://www.codeotaku.com/index
44
- <font color="#00AA00"><b> version</b></font>: h2
45
- <font color="#00AA00"><b> status</b></font>: 200
46
- <font color="#00AA00"><b> body</b></font>: body with length <b>7879B</b>
47
- <b> content-type</b>: &quot;text/html; charset=utf-8&quot;
48
- <b> cache-control</b>: &quot;public, max-age=3600&quot;
49
- <b> expires</b>: &quot;Mon, 04 May 2020 13:23:47 GMT&quot;
50
- <b> server</b>: &quot;falcon/0.36.4&quot;
51
- <b> date</b>: &quot;Mon, 04 May 2020 12:23:47 GMT&quot;
52
- <b> vary</b>: &quot;accept-encoding&quot;
53
- </pre>
54
-
55
- You can specify multiple commands and they will be executed sequentially.
@@ -1,69 +0,0 @@
1
- # Gem Integration
2
-
3
- This guide explains how to add `bake` to a Ruby gem and export standardised tasks for use by other gems and projects.
4
-
5
- ## Exporting Tasks
6
-
7
- Adding a `bake/` directory to your gem will allow other gems and projects to consume those recipes. In order to prevent collisions, you *should* prefix your commands with the name of the gem, e.g. in `mygem/bake/mygem.rb`:
8
-
9
- ~~~ ruby
10
- def setup
11
- # ...
12
- end
13
- ~~~
14
-
15
- Then, in a different project which depends on `mygem`, you can run tasks from `mygem` by invoking them using `bake`:
16
-
17
- ~~~ bash
18
- $ bake mygem:setup
19
- ~~~
20
-
21
- ## Examples
22
-
23
- There are many gems which export tasks in this way. Here are some notable examples:
24
-
25
- ### Variant
26
-
27
- The [variant gem](https://github.com/socketry/variant) exposes bake tasks for setting the environment e.g. `development`, `testing`, or `production`.
28
-
29
- <pre class="terminal">$ bake list variant
30
- <b>Bake::Loader variant-0.1.1</b>
31
-
32
- <b>variant:production</b> <font color="#00AA00">**overrides</font>
33
- <font color="#638FFF">Select the production variant.</font>
34
- <font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
35
-
36
- <b>variant:staging</b> <font color="#00AA00">**overrides</font>
37
- <font color="#638FFF">Select the staging variant.</font>
38
- <font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
39
-
40
- <b>variant:development</b> <font color="#00AA00">**overrides</font>
41
- <font color="#638FFF">Select the development variant.</font>
42
- <font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
43
-
44
- <b>variant:testing</b> <font color="#00AA00">**overrides</font>
45
- <font color="#638FFF">Select the testing variant.</font>
46
- <font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
47
-
48
- <b>variant:force</b> <font color="#AA0000">name</font> <font color="#00AA00">**overrides</font>
49
- <font color="#638FFF">Force a specific variant.</font>
50
- <font color="#00AA00">name</font> [Symbol] <font color="#638FFF">the default variant.</font>
51
- <font color="#00AA00">overrides</font> [Hash] <font color="#638FFF">any specific variant overrides.</font>
52
-
53
- <b>variant:show</b>
54
- <font color="#638FFF">Show variant-related environment variables.</font>
55
- </pre>
56
-
57
- ### Console
58
-
59
- The [console gem](https://github.com/socketry/console) exposes bake tasks to change the log level.
60
-
61
- <pre class="terminal">$ bake list console
62
- <b>Bake::Loader console-1.8.2</b>
63
-
64
- <b>console:info</b>
65
- <font color="#638FFF">Increase the verbosity of the logger to info.</font>
66
-
67
- <b>console:debug</b>
68
- <font color="#638FFF">Increase the verbosity of the logger to debug.</font>
69
- </pre>
@@ -1,64 +0,0 @@
1
- # Project Integration
2
-
3
- This guide explains how to add `bake` to a Ruby project.
4
-
5
- ## Bakefile
6
-
7
- At the top level of your project, you can create a `bake.rb` file, which contains top level tasks which are private to your project.
8
-
9
- ~~~ ruby
10
- def cake
11
- ingredients = call 'supermarket:shop', 'flour,sugar,cocoa'
12
- lookup('mixer:add').call(ingredients)
13
- end
14
- ~~~
15
-
16
- This file is project specific and is the only file which can expose top level tasks (i.e. without a defined namespace). When used in a gem, these tasks are not exposed to other gems/projects.
17
-
18
- ## Recipes
19
-
20
- Alongside the `bake.rb`, there is a `bake/` directory which contains files like `supermarket.rb`. These files contain recipes, e.g.:
21
-
22
- ~~~ ruby
23
- # @param ingredients [Array(Any)] the ingredients to purchase.
24
- def shop(ingredients)
25
- supermarket = Supermarket.best
26
-
27
- return supermarket.purchase(ingredients)
28
- end
29
- ~~~
30
-
31
- These methods are automatically scoped according to the file name, e.g. `bake/supermarket.rb` will define `supermarket:shop`.
32
-
33
-
34
- ## Arguments
35
-
36
- Arguments work as normal. Documented types are used to parse strings from the command line. Both positional and optional parameters are supported.
37
-
38
- ### Positional Parameters
39
-
40
- Positional parameters are non-keyword parameters which may have a default value. However, because of the limits of the command line, all positional arguments must be specified.
41
-
42
- ~~~ ruby
43
- # @param x [Integer]
44
- # @param y [Integer]
45
- def add(x, y)
46
- puts x + y
47
- end
48
- ~~~
49
-
50
- Which is invoked by `bake add 1 2`.
51
-
52
- ### Optional Parameters
53
-
54
- Optional parameters are keyword parameters which may have a default value. The parameter is set on the command line using the name of the parameter followed by an equals sign, followed by the value.
55
-
56
- ~~~ ruby
57
- # @param x [Integer]
58
- # @param y [Integer]
59
- def add(x:, y: 2)
60
- puts x + y
61
- end
62
- ~~~
63
-
64
- Which is invoked by `bake add x=1`. Because `y` is not specified, it will default to `2` as per the method definition.