run_tasks 1.6.0 → 1.7.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 +4 -4
- data/src/run.rb +57 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d28b64a797694474cb625f1359e5ba0cf58316c
|
4
|
+
data.tar.gz: a5de99dc39b841f4a215818410803a777b558dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31fa21481a39c615caa2663f9673717250a2b0ba12c52998d73ea6cbeaf69d4e1797fc0173c765f78aa0df46fbd1f7d6f6ad9d807eb2aa25c5f3b3663fd88cb8
|
7
|
+
data.tar.gz: 585078fa341b255f561951ed5ed9056d73c2d2e79c27d3c6a9b9bf6583facecb7f3184ed6d82799db9491d6381cb324a4996b1b8cabac9db562ad73b9535e6c7
|
data/src/run.rb
CHANGED
@@ -33,24 +33,30 @@ HOMEPAGE = GEM&.homepage
|
|
33
33
|
def task(name, help = nil, &block)
|
34
34
|
if !name.is_a?(Symbol)
|
35
35
|
puts
|
36
|
-
puts "
|
36
|
+
puts "'name' parameter must be a symbol".red
|
37
37
|
exit 6
|
38
38
|
end
|
39
|
-
if !help.nil?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
if !help.nil?
|
40
|
+
if !help.is_a?(String)
|
41
|
+
puts
|
42
|
+
puts "'help' parameter must be a string".red
|
43
|
+
exit 6
|
44
|
+
end
|
45
|
+
else
|
46
|
+
# Load comments directly above the task as help verbatim.
|
45
47
|
caller = caller_locations[0]
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
lines = File.readlines(caller.absolute_path)
|
49
|
+
help = (0..(caller.lineno - 2)).to_a.reverse.reduce([]) do |comments, lineno|
|
50
|
+
match = /^\s*#\s*(?<comment>.+?)\s*$/.match(lines[lineno])
|
51
|
+
break comments if match.nil?
|
52
|
+
comments << match[:comment]
|
53
|
+
comments
|
54
|
+
end.reverse
|
49
55
|
end
|
50
56
|
@tasks.store(
|
51
57
|
name,
|
52
58
|
{
|
53
|
-
:help => help.
|
59
|
+
:help => help.is_a?(String) ? [help] : help,
|
54
60
|
:block => block
|
55
61
|
}
|
56
62
|
)
|
@@ -92,6 +98,34 @@ def are_you_sure?(text = "Are you sure?")
|
|
92
98
|
exit 9 unless answer == "y"
|
93
99
|
end
|
94
100
|
|
101
|
+
def menu(text, choices)
|
102
|
+
labels = nil
|
103
|
+
values = nil
|
104
|
+
choice = nil
|
105
|
+
|
106
|
+
if choices.is_a?(Array)
|
107
|
+
labels = choices
|
108
|
+
values = choices
|
109
|
+
elsif choices.is_a?(Hash)
|
110
|
+
labels = choices.keys
|
111
|
+
values = choices.values
|
112
|
+
else
|
113
|
+
puts "menu() 'choices' parameter must be an Array or an Hash".red
|
114
|
+
exit 10
|
115
|
+
end
|
116
|
+
|
117
|
+
loop do
|
118
|
+
labels.each_with_index do |label, index|
|
119
|
+
puts "#{index + 1}. #{label}"
|
120
|
+
end
|
121
|
+
puts text
|
122
|
+
choice = STDIN.gets.chomp.to_i
|
123
|
+
break if !values[choice - 1].nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
values[choice - 1]
|
127
|
+
end
|
128
|
+
|
95
129
|
# @param uri [String]
|
96
130
|
def require_remote(uri)
|
97
131
|
cache_path = "/tmp/run_cache_#{Digest::MD5.hexdigest(uri)}"
|
@@ -149,7 +183,18 @@ if ARGV.size == 0 || (ARGV.size == 1 && ARGV[0] == "help")
|
|
149
183
|
end
|
150
184
|
# Display each task and their help.
|
151
185
|
@tasks.sort.to_h.each do |name, task|
|
152
|
-
|
186
|
+
if task[:help].size == 0
|
187
|
+
puts " #{name}".yellow
|
188
|
+
next
|
189
|
+
end
|
190
|
+
task[:help].each_with_index do |help, index|
|
191
|
+
help = Markdown::Engine.new(help).to_ansi
|
192
|
+
if index == 0
|
193
|
+
puts " #{name}".yellow + (" " * (max_size - name.size + 4)) + help
|
194
|
+
next
|
195
|
+
end
|
196
|
+
puts (" " * (max_size + 5)) + help
|
197
|
+
end
|
153
198
|
end
|
154
199
|
exit
|
155
200
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: run_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aurélien Delogu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: aurelien.delogu@gmail.com
|