run_tasks 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/run.rb +29 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fa8127bba38224f6ba4c779edae6b71f8f54a00
4
- data.tar.gz: f279a93debf06b7085b0d95358e7f9f1fcb34780
3
+ metadata.gz: a8ca5b6161049b4ab439ac2f9138d50bcea418c8
4
+ data.tar.gz: '0929497d99ff80c07b4dcc434ca10322321653fb'
5
5
  SHA512:
6
- metadata.gz: 86273c44aac9a5d1b447f75f5d606dcd0e14ca365455748adcf7b27a522953b0986fbfa68e768c2cd0d3b7f93f8a2d44bc6736bc1fd29933b0d317d4486870c0
7
- data.tar.gz: f8638842342a3a39744d2ff6f24b6007138d97c9ce28929fabb47754fd2bd9124619209d370614e5e7d6770f28346b80c4bcc2f69d8e532176f859fbc5c32194
6
+ metadata.gz: 38b289ecbb3e0a0bb3cd0fa6fc0dc7872a6d9d2331bd9c3584f18a3eeaa220c5a3f9d2649b3ce0b1808c323b674329614e68342ecc5e12d3eb78cb142c883db2
7
+ data.tar.gz: a2aff1ef595a7e9e3d16417c25314a3bb9a452795f807f13e6dda09e5eb0b9baaa62ce45bdf0136d07787de1b4597ea992052baa6c429f0af302b3c54ca0116e
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 "First task parameter must be a symbol".red
36
+ puts "'name' parameter must be a symbol".red
37
37
  exit 6
38
38
  end
39
- if !help.nil? && !help.is_a?(String)
40
- puts
41
- puts "Second task parameter must be a string".red
42
- exit 6
43
- end
44
- if help.nil?
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
- line = File.readlines(caller.absolute_path)[caller.lineno - 2]
47
- match = /^\s*#\s*(?<comment>.+?)\s*$/.match(line)
48
- help = match[:comment] if !match.nil?
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.nil? ? "" : Markdown::Engine.new(help).to_ansi,
59
+ :help => help.is_a?(String) ? [help] : help,
54
60
  :block => block
55
61
  }
56
62
  )
@@ -149,7 +155,18 @@ if ARGV.size == 0 || (ARGV.size == 1 && ARGV[0] == "help")
149
155
  end
150
156
  # Display each task and their help.
151
157
  @tasks.sort.to_h.each do |name, task|
152
- puts " #{name}".yellow + (" " * (max_size - name.size + 4)) + task[:help]
158
+ if task[:help].size == 0
159
+ puts " #{name}".yellow
160
+ next
161
+ end
162
+ task[:help].each_with_index do |help, index|
163
+ help = Markdown::Engine.new(help).to_ansi
164
+ if index == 0
165
+ puts " #{name}".yellow + (" " * (max_size - name.size + 4)) + help
166
+ next
167
+ end
168
+ puts (" " * (max_size + 5)) + help
169
+ end
153
170
  end
154
171
  exit
155
172
  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: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Delogu