bake 0.17.0 → 0.18.2

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: 10135085caa64994c79251726699d674223c0e4441d937cc548f56893b8ba331
4
- data.tar.gz: ca1a86f96716c5a7e1827b49b3eefd06164295f0ab5621b007d5bd727bbba76a
3
+ metadata.gz: a3bcf5cd8672eaa2a698d0df26ac16b853d574ff386f2134e2540b6a601cfaa1
4
+ data.tar.gz: d06efeba9bd097c2f5bad7adf529a970a8fe9e010540a6b1d8449d1d3897b005
5
5
  SHA512:
6
- metadata.gz: d3db37001328e050c50adb89d6d2cd7e0cdef54f3b54ae2225d676b05e7ff735be19ba2056912e571ce5185f7a7336e334809b66c5312da1e0dbd798b4d87b3a
7
- data.tar.gz: feb7ea189a4841a2b08ab43aa4a683ada9b19bb5fe8a189ba888b945bc8e1c85501e564030b883cf28eb24d9348e1fdbbf93a605ea1111245f29e4bb5469109d
6
+ metadata.gz: 8fa7311b0fd77dc5388801f2aeca08395ad9499df10008b087b1bbc172ec131cf57827aceb19dff1d1365d4cbce58975f9cb9addbed830971546297e35411e41
7
+ data.tar.gz: 7ca9417bfb9d2659113c517e4f8ef530bd4fd7d54617e6ea1931694ab2b036dba4d18f092d3403a6cd76ea930b67cc0dc2112c8058cc947bcd67a7f240d27356
checksums.yaml.gz.sig CHANGED
Binary file
data/bake/input.rb ADDED
@@ -0,0 +1,47 @@
1
+
2
+ FORMATS = {
3
+ json: ->(file){require 'json'; JSON.parse(file.read)},
4
+ yaml: ->(file){require 'yaml'; YAML.load(file.read)},
5
+ }
6
+
7
+ # Parse an input file (defaulting to stdin) in the specified format. The format can be extracted from the file extension if left unspecified.
8
+ # @parameter file [Input] The input file.
9
+ # @parameter format [Symbol] The input format, e.g. json, yaml.
10
+ def input(file: $stdin, format: nil)
11
+ if format = format_for(file, format)
12
+ format.call(file)
13
+ else
14
+ raise "Unable to determine input format of #{file}!"
15
+ end
16
+ end
17
+
18
+ # Parse some input text in the specified format (defaulting to JSON).
19
+ # @parameter text [String] The input text.
20
+ # @parameter format [Symbol] The input format, e.g. json, yaml.
21
+ def parse(text, format: :json)
22
+ file = StringIO.new(text)
23
+
24
+ if format = format_for(nil, format)
25
+ format.call(file)
26
+ else
27
+ raise "Unable to determine input format!"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def format_for(file, name)
34
+ if file.respond_to?(:path) and path = file.path
35
+ name ||= file_type(path)
36
+ end
37
+
38
+ FORMATS[name]
39
+ end
40
+
41
+ def file_type(path)
42
+ if extension = File.extname(path)
43
+ extension.sub!(/\A\./, '')
44
+ return if extension.empty?
45
+ return extension.to_sym
46
+ end
47
+ end
data/bake/output.rb ADDED
@@ -0,0 +1,42 @@
1
+
2
+ FORMATS = {
3
+ json: ->(file, value){require 'json'; file.puts(JSON.pretty_generate(value))},
4
+ pp: ->(file, value){require 'pp'; PP.pp(value, file)},
5
+ raw: ->(file, value){file.puts(value)},
6
+ yaml: ->(file, value){require 'yaml'; file.puts(YAML.dump(value))},
7
+ }
8
+
9
+ # Dump the last result to the specified file (defaulting to stdout) in the specified format (defaulting to Ruby's pretty print).
10
+ # @parameter file [Output] The input file.
11
+ # @parameter format [Symbol] The output format.
12
+ def output(input:, file: $stdout, format: nil)
13
+ if format = format_for(file, format)
14
+ format.call(file, input)
15
+ else
16
+ raise "Unable to determine output format!"
17
+ end
18
+
19
+ # Allow chaining of output processing:
20
+ return input
21
+ end
22
+
23
+ private
24
+
25
+ def format_for(file, name)
26
+ if file.respond_to?(:path) and path = file.path
27
+ name ||= file_type(path)
28
+ end
29
+
30
+ # Default to pretty print:
31
+ name ||= :pp
32
+
33
+ FORMATS[name]
34
+ end
35
+
36
+ def file_type(path)
37
+ if extension = File.extname(path)
38
+ extension.sub!(/\A\./, '')
39
+ return if extension.empty?
40
+ return extension.to_sym
41
+ end
42
+ end
@@ -26,11 +26,14 @@ require_relative 'documentation'
26
26
  module Bake
27
27
  # Structured access to arguments.
28
28
  class Arguments
29
- def self.extract(recipe, arguments)
30
- self.new(recipe).extract(arguments)
29
+ def self.extract(recipe, arguments, **defaults)
30
+ # Only supply defaults that match the recipe option names:
31
+ defaults = defaults.slice(*recipe.required_options)
32
+
33
+ self.new(recipe, defaults).extract(arguments)
31
34
  end
32
35
 
33
- def initialize(recipe)
36
+ def initialize(recipe, defaults)
34
37
  @recipe = recipe
35
38
 
36
39
  @types = recipe.types
@@ -38,7 +41,7 @@ module Bake
38
41
  @arity = recipe.arity
39
42
 
40
43
  @ordered = []
41
- @options = {}
44
+ @options = defaults
42
45
  end
43
46
 
44
47
  attr :ordered
@@ -32,17 +32,6 @@ module Bake
32
32
  class Call < Samovar::Command
33
33
  self.description = "Execute one or more commands."
34
34
 
35
- OUTPUT = {
36
- json: ->(value){require 'json'; $stdout.puts(JSON.pretty_generate(value))},
37
- pp: ->(value){require 'pp'; PP.pp(value, $stdout)},
38
- raw: ->(value){$stdout.puts(value)},
39
- yaml: ->(value){require 'yaml'; $stdout.puts(YAML.dump(value))},
40
- }
41
-
42
- options do
43
- option "-o/--output <format>", "Output the result of the last task in the given format: #{OUTPUT.keys.join(", ")}.", type: Symbol
44
- end
45
-
46
35
  def bakefile
47
36
  @parent.bakefile
48
37
  end
@@ -58,11 +47,7 @@ module Bake
58
47
  def call
59
48
  context = @parent.context
60
49
 
61
- last_result = context.call(*@commands)
62
-
63
- if output = @options[:output]
64
- format(output, last_result)
65
- end
50
+ context.call(*@commands)
66
51
  end
67
52
  end
68
53
  end
data/lib/bake/context.rb CHANGED
@@ -118,7 +118,7 @@ module Bake
118
118
 
119
119
  while command = commands.shift
120
120
  if recipe = @recipes[command]
121
- arguments, options = recipe.prepare(commands)
121
+ arguments, options = recipe.prepare(commands, last_result)
122
122
  last_result = recipe.call(*arguments, **options)
123
123
  else
124
124
  raise ArgumentError, "Could not find recipe for #{command}!"
@@ -81,7 +81,7 @@ module Bake
81
81
  end
82
82
  end
83
83
 
84
- PARAMETER = /\A\s*@param(eter)?\s+(?<name>.*?)\s+\[(?<type>.*?)\](\s+(?<details>.*?))?\z/
84
+ PARAMETER = /\A@param(eter)?\s+(?<name>.*?)\s+\[(?<type>.*?)\](\s+(?<details>.*?))?\z/
85
85
 
86
86
  # The parameter lines of the comment block.
87
87
  # e.g. `@parameter value [String] The value.`
data/lib/bake/loaders.rb CHANGED
@@ -83,6 +83,8 @@ module Bake
83
83
  # @parameter current [String] The path to start searching from.
84
84
  def append_from_root(current = Dir.pwd, **options)
85
85
  while current
86
+ Console.logger.debug(self) {"Checking current #{current}..."}
87
+
86
88
  append_path(current, **options)
87
89
 
88
90
  parent = File.dirname(current)
data/lib/bake/recipe.rb CHANGED
@@ -85,6 +85,16 @@ module Bake
85
85
  end
86
86
  end
87
87
 
88
+ def required_options
89
+ if parameters = self.parameters
90
+ parameters.map do |(type, name)|
91
+ if type == :keyreq
92
+ name
93
+ end
94
+ end.compact
95
+ end
96
+ end
97
+
88
98
  # The command name for this recipe.
89
99
  def command
90
100
  @command ||= compute_command
@@ -107,8 +117,8 @@ module Bake
107
117
  # @parameter arguments [Array(String)] The command line arguments
108
118
  # @returns ordered [Array]
109
119
  # @returns options [Hash]
110
- def prepare(arguments)
111
- Arguments.extract(self, arguments)
120
+ def prepare(arguments, last_result = nil)
121
+ Arguments.extract(self, arguments, input: last_result)
112
122
  end
113
123
 
114
124
  # Call the recipe with the specified arguments and options.
@@ -33,8 +33,8 @@ module Bake
33
33
  false
34
34
  end
35
35
 
36
- def self.parse(value)
37
- BigDecimal(value)
36
+ def self.parse(input)
37
+ BigDecimal(input)
38
38
  end
39
39
  end
40
40
  end
@@ -31,8 +31,8 @@ module Bake
31
31
  false
32
32
  end
33
33
 
34
- def self.parse(value)
35
- value.to_f
34
+ def self.parse(input)
35
+ input.to_f
36
36
  end
37
37
  end
38
38
  end
@@ -31,8 +31,8 @@ module Bake
31
31
  false
32
32
  end
33
33
 
34
- def self.parse(value)
35
- Integer(value)
34
+ def self.parse(input)
35
+ Integer(input)
36
36
  end
37
37
  end
38
38
  end
@@ -31,8 +31,8 @@ module Bake
31
31
  false
32
32
  end
33
33
 
34
- def self.parse(value)
35
- value.to_s
34
+ def self.parse(input)
35
+ input.to_s
36
36
  end
37
37
  end
38
38
  end
data/lib/bake/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Bake
24
- VERSION = "0.17.0"
24
+ VERSION = "0.18.2"
25
25
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
38
38
  HiLJ8VOFx6w=
39
39
  -----END CERTIFICATE-----
40
- date: 2022-05-21 00:00:00.000000000 Z
40
+ date: 2022-05-22 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: samovar
@@ -102,6 +102,8 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - bake/input.rb
106
+ - bake/output.rb
105
107
  - bin/bake
106
108
  - lib/bake.rb
107
109
  - lib/bake/arguments.rb
@@ -151,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
153
  - !ruby/object:Gem::Version
152
154
  version: '0'
153
155
  requirements: []
154
- rubygems_version: 3.1.6
156
+ rubygems_version: 3.3.7
155
157
  signing_key:
156
158
  specification_version: 4
157
159
  summary: A replacement for rake with a simpler syntax.
metadata.gz.sig CHANGED
Binary file