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 +4 -4
- data/README.md +10 -0
- data/src/run/core.rb +25 -0
- data/src/run/error/runfile_version_mismatch.rb +7 -2
- data/src/run/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89b89a1b7418844bef966d37027b641a162cbcd4023a2e932a1848ccf3df69bc
|
|
4
|
+
data.tar.gz: d691b13bf7a3eab7ebc5bbbb9f5155c88686696667c8a305aa4ca9ce6cbd2c79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
7
|
-
|
|
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