bake 0.14.2 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b596d8fcdd2daa879fedc00f65aac1696b04b40ab1a727d7617566411557c730
4
- data.tar.gz: 8281d5f3337188820811cb3ecf4a4b735fb517e90222c8a2c82e0fb3ce8d59de
3
+ metadata.gz: e9aacfa1d30a7a1c8c888d399ea3d24c9f8039b5a58d3c6e6444be9bdaa39910
4
+ data.tar.gz: e3b8d501ac13f9346d1bf07fcee7314bde74eeccd9bb7cfe119819913dd568da
5
5
  SHA512:
6
- metadata.gz: 9419bc5577aa2765bd15232d5bd2340b6b92584f795480d874800b4d163b25623a96291fbfa853317079e7de0e481b8b960bf5ecae0cd653c6743369a4f8fdda
7
- data.tar.gz: 96b4996147f6c8a3fe4408c8027f2a407d431de472445a1739e096d08353117ced32bf02e9a07470f50248011d7fc506f20bb5e886e26dc6a0ab4b09efb0f5cd
6
+ metadata.gz: dc423bf25a37828f28fe9a508976d54c6913223e1507b46ae19e9ffd5e8d9a8254a37bc174e9025425acdc3b847d1929389bc799c5154801e28d96b4e8d8e352
7
+ data.tar.gz: 816410e988ba73a4f6ca130ab27cce179ea18d791ed8811e20ebad9e036f5a486c9a1f3e8122d057e3f253c5700ef1ed6bfc502a0bbbf1a5e77d24a00156581a
@@ -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
@@ -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
@@ -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
@@ -105,40 +106,7 @@ module Bake
105
106
  # @returns ordered [Array]
106
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.
@@ -171,6 +139,19 @@ module Bake
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
 
@@ -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
@@ -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
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Bake
22
- VERSION = "0.14.2"
22
+ VERSION = "0.15.0"
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.14.2
4
+ version: 0.15.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-09-02 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: samovar
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - bin/bake
77
77
  - lib/bake.rb
78
+ - lib/bake/arguments.rb
78
79
  - lib/bake/base.rb
79
80
  - lib/bake/command.rb
80
81
  - lib/bake/command/call.rb