run_tasks 1.2.7 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/src/run/markdown.rb +4 -4
  3. data/src/run.rb +21 -14
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da3ec2cfa88571c506d40137ccf45d89ee9fbee8929d90ae8473655283b6d670
4
- data.tar.gz: f16ab0960472b63733244160e327844baeb3151d29434a7bd56948444df074a9
3
+ metadata.gz: defef3f4c383f104dbdd29d887667fd4dc78ab7f6126df67f9c2a164273edb05
4
+ data.tar.gz: 82b310b715b998b76ff8269cc36760dfee621915796e736ff8850247c2aa427b
5
5
  SHA512:
6
- metadata.gz: d201af5c988bfad270cac3a72b4128bb2abd8366631bd84f1e35883662e84ce9e620769ede8d9fbff83ee74fe2c85a399a573ce3d082dd07d3f7cb857eb22efc
7
- data.tar.gz: caa52f6153fb91d953a0e25218e8a62493b0fb35bc3c3c2af7488cc96f93285c2e6ae1117a509f9df86c7b6c86d84ad203416cd0c82eaa4519ac84ae2c9e91ad
6
+ metadata.gz: 1db823df990b780814e452ec8911efaae7c9d80448d075cc1af5b342b4b09e7f3a46074d8b919d517846dfa91a0ae4fd35a670d6093a28384b1edccc9b9c815d
7
+ data.tar.gz: 94fab98a5b6d052bc225ba2c363e741a61d7b206f7bb9f50b0047ef830a72118599a9f5b8703d40530df1bbcbb6e1d3dba4580addb38b5301d5d27f284816614
data/src/run/markdown.rb CHANGED
@@ -16,19 +16,19 @@ class Markdown
16
16
  private
17
17
 
18
18
  def bold(string)
19
- string.gsub(/([^*_])[*_]{2}([^*_]+)[*_]{2}([^*_])/) do
19
+ string.gsub(/([^*_]|^)[*_]{2}([^*_]+)[*_]{2}([^*_]|$)/) do
20
20
  Regexp.last_match[1] + Regexp.last_match[2].bold + Regexp.last_match[3]
21
21
  end
22
22
  end
23
23
 
24
24
  def code(string)
25
- string.gsub(/([^`])`([^*_]+)`([^`])/) do
26
- Regexp.last_match[1] + Regexp.last_match[2].blue.inverse + Regexp.last_match[3]
25
+ string.gsub(/([^`]|^)`([^*_]+)`([^`]|$)/) do
26
+ Regexp.last_match[1] + Regexp.last_match[2].cyan + Regexp.last_match[3]
27
27
  end
28
28
  end
29
29
 
30
30
  def italic(string)
31
- string.gsub(/([^*_])[*_]{1}([^*_]+)[*_]{1}([^*_])/) do
31
+ string.gsub(/([^*_]|^)[*_]{1}([^*_]+)[*_]{1}([^*_]|$)/) do
32
32
  Regexp.last_match[1] + Regexp.last_match[2].italic + Regexp.last_match[3]
33
33
  end
34
34
  end
data/src/run.rb CHANGED
@@ -27,7 +27,9 @@ HOMEPAGE = GEM&.homepage
27
27
 
28
28
  @tasks = Hash.new
29
29
 
30
- # Define a task.
30
+ # @param name [Symbol]
31
+ # @param help [String]
32
+ # @yield [*Array, **Hash]
31
33
  def task(name, help = "", &block)
32
34
  if !name.is_a?(Symbol)
33
35
  puts
@@ -50,16 +52,18 @@ def task(name, help = "", &block)
50
52
  )
51
53
  end
52
54
 
53
- # Call a task.
54
- def call(name, *arguments, **options)
55
- @tasks[name][:block].call *arguments, **options
56
- end
55
+ # @param task_name_or_command [Symbol, String]
56
+ # @param arguments [Array] Optional arguments sent to the task.
57
+ # @param options [Hash] Optional options sent to the task.
58
+ def run(task_name_or_command, *arguments, **options)
59
+ if task_name_or_command.is_a?(Symbol)
60
+ @tasks[task_name_or_command][:block].call *arguments, **options
61
+ return
62
+ end
57
63
 
58
- # Run a shell command.
59
- def shell(command)
60
- puts ">".bright_blue + " #{command}".bright_white
64
+ puts ">".bright_blue + " #{task_name_or_command}".bright_white
61
65
  puts
62
- case system(command)
66
+ case system(task_name_or_command)
63
67
  when false
64
68
  puts
65
69
  puts "The command has exited with return code: #{$?.exitstatus}.".magenta
@@ -74,6 +78,7 @@ def shell(command)
74
78
  puts
75
79
  end
76
80
 
81
+ # @param uri [String]
77
82
  def require_remote(uri)
78
83
  cache_path = "/tmp/run_cache_#{Digest::MD5.hexdigest(uri)}"
79
84
  if !File.exists? cache_path
@@ -88,6 +93,7 @@ rescue => error
88
93
  exit 8
89
94
  end
90
95
 
96
+ # @param name [String]
91
97
  def require_extension(name)
92
98
  require_remote "https://pyrsmk.fra1.cdn.digitaloceanspaces.com" \
93
99
  "/run_extensions/#{name}.rb"
@@ -106,9 +112,10 @@ end
106
112
 
107
113
  begin
108
114
  require "./#{RUNFILE}"
109
- rescue SyntaxError
115
+ rescue SyntaxError => error
110
116
  puts
111
- puts "The Runfile contains a syntax error.".red
117
+ puts "The Runfile contains a syntax error:".red
118
+ puts error.message.red
112
119
  puts
113
120
  exit 5
114
121
  end
@@ -148,8 +155,8 @@ if VERSION && HOMEPAGE
148
155
  current = VERSION.split "."
149
156
  latest = version[1].split "."
150
157
  if current[0].to_i < latest[0].to_i ||
151
- current[1].to_i < latest[1].to_i ||
152
- current[2].to_i < latest[2].to_i
158
+ current[1].to_i < latest[1].to_i ||
159
+ current[2].to_i < latest[2].to_i
153
160
  puts "New ".cyan + version[1].yellow + " version released!".cyan
154
161
  puts
155
162
  puts "You can upgrade with:".cyan + "gem update run_tasks".yellow
@@ -170,7 +177,7 @@ if !@tasks.include?(name)
170
177
  exit 2
171
178
  end
172
179
  begin
173
- call name, *ARGV.slice(1..)
180
+ run(name, *ARGV.slice(1..))
174
181
  rescue Interrupt
175
182
  exit 3
176
183
  rescue => error
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.2.7
4
+ version: 1.3.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-02-14 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: aurelien.delogu@gmail.com