run_tasks 4.0.0 → 4.0.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: 18567c31d63e5cacb71de0cf93a2a988a36161add471ba464e0c76fc80e1a5ae
4
- data.tar.gz: 5e1a9ca0f82fe57c4ebab2bafe9487f588fa436f0c2a14b4e2555bace0874000
3
+ metadata.gz: 89b89a1b7418844bef966d37027b641a162cbcd4023a2e932a1848ccf3df69bc
4
+ data.tar.gz: d691b13bf7a3eab7ebc5bbbb9f5155c88686696667c8a305aa4ca9ce6cbd2c79
5
5
  SHA512:
6
- metadata.gz: b70d57d950528c6182766218104938627b2b9469baccebd1e4472f3ef8ec1363283dd2432d898b4d89bc8173e3a249acfdc02b7fa7eeed99e5598323599cd5eb
7
- data.tar.gz: 8ba35fe28b3ef9346ff031041b342d641975503d068f9e817df178a429a663a11af423b1f3e1f1c03622043013513603b5b98b57cf10cfbbc5cbf759d9fefd2f
6
+ metadata.gz: 780a926350e17a09469794beb7e0fb8959df42ee893dd209436f1b85aefe2aca749a235060dc16764da502f0007b415421fadfa2294c8e66cc855b7eaf1f2a4d
7
+ data.tar.gz: 1ee1f1e74ae13f7962184f1e7134621fefb298068c89121af734bc7f74788b243c20f2554732491366635aea67e73d573f6f2c8ce96f572964d6d682a6aa1868
data/README.md CHANGED
@@ -34,6 +34,16 @@ run help
34
34
 
35
35
  > Note that the command `run` displays the help screen by default when no task is specified.
36
36
 
37
+ ## Runfile version
38
+
39
+ The first line of a Runfile declares the major version of Run it is written for:
40
+
41
+ ```rb
42
+ version 4
43
+ ```
44
+
45
+ When a Runfile declares another major version, Run hands over to the matching version if it is installed, so projects written for Run 3 and Run 4 can live side by side. A Runfile without this line is a version 2 one.
46
+
37
47
  ## Writing tasks
38
48
 
39
49
  ```rb
data/src/run/core.rb CHANGED
@@ -7,6 +7,7 @@ module Run
7
7
  NAME_PATTERN = /[a-zA-Z_]\w*(?:-\w+)*/
8
8
  OPTION_PATTERN = /\A([+-])(#{NAME_PATTERN})\z/
9
9
  NAMED_PARAMETER_PATTERN = /\A(#{NAME_PATTERN})=(.*)\z/m
10
+ RUNFILE_VERSION_PATTERN = /^\s*version\s*\(?\s*(\d+)/
10
11
  @@tasks = []
11
12
  @@runfile_version = nil
12
13
 
@@ -18,6 +19,7 @@ module Run
18
19
 
19
20
  # @return [void]
20
21
  def self.run_run
22
+ delegate_to_runfile_version! if File.file?(RUNFILE_FILENAME)
21
23
  if ARGV.size == 1 && ARGV[0] == "--completions"
22
24
  require File.expand_path(RUNFILE_FILENAME) if File.exist?(RUNFILE_FILENAME)
23
25
  puts completions.join("\n")
@@ -72,8 +74,31 @@ module Run
72
74
  }
73
75
  end
74
76
 
77
+ # @param contents [String]
78
+ # @return [Integer]
79
+ def self.declared_runfile_version(contents)
80
+ contents[RUNFILE_VERSION_PATTERN, 1]&.to_i || 2
81
+ end
82
+
83
+ # @param major [Integer]
84
+ # @return [Gem::Version, nil]
85
+ def self.installed_version_for(major)
86
+ Gem::Specification.find_all_by_name("run_tasks", "~> #{major}.0").map(&:version).max
87
+ end
88
+
75
89
  private
76
90
 
91
+ # @return [void]
92
+ def self.delegate_to_runfile_version!
93
+ major = declared_runfile_version(File.read(RUNFILE_FILENAME))
94
+ return if major == VERSION.split(".").first.to_i
95
+
96
+ version = installed_version_for(major)
97
+ raise Run::Error::RunfileVersionMismatch.new(major) if !version
98
+
99
+ exec Gem.ruby, File.join(Gem.bindir, "run"), "_#{version}_", *ARGV
100
+ end
101
+
77
102
  # @return [void]
78
103
  def self.check_runfile_version!
79
104
  if (@@runfile_version || 2) != VERSION.split(".").first.to_i
@@ -3,8 +3,13 @@
3
3
  module Run
4
4
  module Error
5
5
  class RunfileVersionMismatch < StandardError
6
- def initialize
7
- super "Runfile version mismatches Run version"
6
+ # @param major [Integer, nil]
7
+ def initialize(major = nil)
8
+ if major
9
+ super "Runfile declares version #{major}, which needs Run #{major}: gem install run_tasks -v '~> #{major}.0'"
10
+ else
11
+ super "Runfile version mismatches Run version"
12
+ end
8
13
  end
9
14
  end
10
15
  end
data/src/run/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Run
4
- VERSION = "4.0.0"
4
+ VERSION = "4.0.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Delogu