run_tasks 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/src/run.rb +186 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa448cfc81715ee0e119156894c878e930db5ae87df88cf345eaaa511c4437ca
|
4
|
+
data.tar.gz: 270a35d0799897cc815698f255fcf8510459a7c491aa78efba447fd1e61e9624
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8fcf053732cefdd93ecda30e3292cb3b739750854b7958adb74234be7f2de6e278e725a81751b0507e8ce175bf30b69a1cb53a9970c568d66f822fda361f78ca
|
7
|
+
data.tar.gz: 02200ead077b339b4c40ba1d142943631777f1bf3fdbea76099f1e8fe2ded0ec3d5d8d3eee72432f7c74fa3a82e2185587f7e9d8158d34fbc86f745b6dcaf01e
|
data/src/run.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
require "fileutils"
|
5
|
+
require "open-uri"
|
6
|
+
require "readline"
|
7
|
+
require "rubygems"
|
8
|
+
require "securerandom"
|
9
|
+
|
10
|
+
GEM = Gem::Specification::load("#{__dir__}/../run.gemspec")
|
11
|
+
VERSION = GEM.version
|
12
|
+
HOMEPAGE = GEM.homepage
|
13
|
+
|
14
|
+
##########################################################################################
|
15
|
+
|
16
|
+
class String
|
17
|
+
@@colors = {
|
18
|
+
:black => "30",
|
19
|
+
:red => "31",
|
20
|
+
:green => "32",
|
21
|
+
:yellow => "33",
|
22
|
+
:blue => "34",
|
23
|
+
:magenta => "35",
|
24
|
+
:cyan => "36",
|
25
|
+
:white => "37",
|
26
|
+
:bright_black => "30;1",
|
27
|
+
:bright_red => "31;1",
|
28
|
+
:bright_green => "32;1",
|
29
|
+
:bright_yellow => "33;1",
|
30
|
+
:bright_blue => "34;1",
|
31
|
+
:bright_magenta => "35;1",
|
32
|
+
:bright_cyan => "36;1",
|
33
|
+
:bright_white => "37;1",
|
34
|
+
}
|
35
|
+
|
36
|
+
def colorize(color)
|
37
|
+
"\033[#{@@colors[color.to_sym]}m#{self}\033[0m"
|
38
|
+
end
|
39
|
+
|
40
|
+
def black; colorize(:black); end
|
41
|
+
def red; colorize(:red); end
|
42
|
+
def green; colorize(:green); end
|
43
|
+
def yellow; colorize(:yellow); end
|
44
|
+
def blue; colorize(:blue); end
|
45
|
+
def magenta; colorize(:magenta); end
|
46
|
+
def cyan; colorize(:cyan); end
|
47
|
+
def white; colorize(:white); end
|
48
|
+
def bright_black; colorize(:bright_black); end
|
49
|
+
def bright_red; colorize(:bright_red); end
|
50
|
+
def bright_green; colorize(:bright_green); end
|
51
|
+
def bright_yellow; colorize(:bright_yellow); end
|
52
|
+
def bright_blue; colorize(:bright_blue); end
|
53
|
+
def bright_magenta; colorize(:bright_magenta); end
|
54
|
+
def bright_cyan; colorize(:bright_cyan); end
|
55
|
+
def bright_white; colorize(:bright_white); end
|
56
|
+
end
|
57
|
+
|
58
|
+
##########################################################################################
|
59
|
+
|
60
|
+
@tasks = Hash.new
|
61
|
+
|
62
|
+
# Define a task.
|
63
|
+
def task(name, help = "", &block)
|
64
|
+
if !name.is_a?(Symbol)
|
65
|
+
puts "first task parameter must be a symbol"
|
66
|
+
exit 6
|
67
|
+
end
|
68
|
+
if !help.is_a?(String)
|
69
|
+
puts "second task parameter must be a string"
|
70
|
+
exit 6
|
71
|
+
end
|
72
|
+
@tasks.store(name, { :help => help, :block => block })
|
73
|
+
end
|
74
|
+
|
75
|
+
# Call a task.
|
76
|
+
def call(name, *arguments, **options)
|
77
|
+
@tasks[name][:block].call *arguments, **options
|
78
|
+
end
|
79
|
+
|
80
|
+
# Run a shell command.
|
81
|
+
def shell(command)
|
82
|
+
puts ">".bright_blue + " #{command}".bright_white
|
83
|
+
puts
|
84
|
+
case system(command)
|
85
|
+
when false
|
86
|
+
puts
|
87
|
+
puts "The command has exited with return code: #{$?.exitstatus}.".magenta
|
88
|
+
puts
|
89
|
+
raise Interrupt.new
|
90
|
+
when nil
|
91
|
+
puts
|
92
|
+
puts "The command has failed.".magenta
|
93
|
+
puts
|
94
|
+
raise Interrupt.new
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def require_remote(uri)
|
99
|
+
cache_path = "/tmp/run_cache_#{Digest::MD5.hexdigest(uri)}"
|
100
|
+
if !File.exists? cache_path
|
101
|
+
File.write(cache_path, URI.parse(uri).open.read)
|
102
|
+
end
|
103
|
+
eval File.read(cache_path)
|
104
|
+
rescue => error
|
105
|
+
puts "Unable to load #{uri}:".red
|
106
|
+
puts "#{error.class}: #{error.message}".red
|
107
|
+
exit 8
|
108
|
+
end
|
109
|
+
|
110
|
+
def require_extension(name)
|
111
|
+
require_remote "https://pyrsmk.fra1.cdn.digitaloceanspaces.com" \
|
112
|
+
"/run_extensions/#{name}.rb"
|
113
|
+
end
|
114
|
+
|
115
|
+
##########################################################################################
|
116
|
+
|
117
|
+
RUNFILE = "Runfile.rb"
|
118
|
+
|
119
|
+
if !File.exists?(RUNFILE)
|
120
|
+
puts "#{RUNFILE} does not exist"
|
121
|
+
exit 7
|
122
|
+
end
|
123
|
+
|
124
|
+
begin
|
125
|
+
require "./#{RUNFILE}"
|
126
|
+
rescue SyntaxError
|
127
|
+
puts "The Runfile contains a syntax error.".red
|
128
|
+
exit 5
|
129
|
+
end
|
130
|
+
|
131
|
+
##########################################################################################
|
132
|
+
|
133
|
+
# Show the help screen if there is no provided task, or if it's explicitly requested.
|
134
|
+
if ARGV.size == 0 || (ARGV.size == 1 && ARGV[0] == "help")
|
135
|
+
puts
|
136
|
+
puts " Run v#{VERSION}".bright_blue
|
137
|
+
puts
|
138
|
+
# Compute the max task names size.
|
139
|
+
max_size = @tasks.keys.reduce(0) do |max, name|
|
140
|
+
next max if name.size <= max
|
141
|
+
name.size
|
142
|
+
end
|
143
|
+
# Display each task and their help.
|
144
|
+
@tasks.sort.to_h.each do |name, task|
|
145
|
+
puts " #{name}".yellow + (" " * (max_size - name.size + 4)) + task[:help]
|
146
|
+
end
|
147
|
+
exit
|
148
|
+
end
|
149
|
+
|
150
|
+
# Verify the latest release version.
|
151
|
+
Thread.new do
|
152
|
+
contents = URI.parse("#{HOMEPAGE}/master/run.gemspec")
|
153
|
+
.open
|
154
|
+
.read
|
155
|
+
version = /^\s*s.version\s*=\s*"(.+?)"\s*$/.match(contents)
|
156
|
+
if !version.nil?
|
157
|
+
next if File.exists?("/tmp/run_dismiss_#{version}")
|
158
|
+
current = VERSION.split "."
|
159
|
+
latest = version[1].split "."
|
160
|
+
if current[0].to_i < latest[0].to_i ||
|
161
|
+
current[1].to_i < latest[1].to_i ||
|
162
|
+
current[2].to_i < latest[2].to_i
|
163
|
+
puts "New ".cyan + version[1].yellow + " version released!".cyan
|
164
|
+
puts
|
165
|
+
puts "You can upgrade with:".cyan + "gem update run_tasks".yellow
|
166
|
+
puts
|
167
|
+
File.write "/tmp/run_dismiss_#{version}", ""
|
168
|
+
end
|
169
|
+
end
|
170
|
+
rescue
|
171
|
+
end
|
172
|
+
|
173
|
+
# Run the requested task.
|
174
|
+
name = ARGV[0].to_sym
|
175
|
+
if !@tasks.include?(name)
|
176
|
+
puts "Unknown '#{name}' task"
|
177
|
+
exit 2
|
178
|
+
end
|
179
|
+
begin
|
180
|
+
call name, *ARGV.slice(1..)
|
181
|
+
rescue Interrupt
|
182
|
+
exit 3
|
183
|
+
rescue => error
|
184
|
+
puts error.message.red
|
185
|
+
exit 4
|
186
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: run_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aurélien Delogu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: aurelien.delogu@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- src/run.rb
|
20
|
+
homepage: https://github.com/pyrsmk/run
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.1.6
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Run project tasks with ease
|
43
|
+
test_files: []
|