run_tasks 1.4.1 → 1.6.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/run.rb +21 -5
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f8a01e9cf83e14af770fdf07028b7eeef28e5a2
4
- data.tar.gz: 6298e13d2b841b1e66f3c095538fd99ea486346c
3
+ metadata.gz: 9fa8127bba38224f6ba4c779edae6b71f8f54a00
4
+ data.tar.gz: f279a93debf06b7085b0d95358e7f9f1fcb34780
5
5
  SHA512:
6
- metadata.gz: 840a4dea8f6978e7a4b48d48afe7148707a127a8d619698ffc7ffe11854996422b1aefe1c52be023728e9f8faf4e2fd61f0034b9821a03c43cecef7d20dec637
7
- data.tar.gz: 0d3d3b5d42de907bf85acd67f14698231756af2c08c5c767aa6bd762aa2085cf83b770bdbc60f58ad8e9790710a4e9f167d8837c63ecd8f10b8fa6add574ff27
6
+ metadata.gz: 86273c44aac9a5d1b447f75f5d606dcd0e14ca365455748adcf7b27a522953b0986fbfa68e768c2cd0d3b7f93f8a2d44bc6736bc1fd29933b0d317d4486870c0
7
+ data.tar.gz: f8638842342a3a39744d2ff6f24b6007138d97c9ce28929fabb47754fd2bd9124619209d370614e5e7d6770f28346b80c4bcc2f69d8e532176f859fbc5c32194
data/src/run.rb CHANGED
@@ -25,26 +25,32 @@ HOMEPAGE = GEM&.homepage
25
25
 
26
26
  ##########################################################################################
27
27
 
28
- @tasks = Hash.new
28
+ @tasks = {}
29
29
 
30
30
  # @param name [Symbol]
31
31
  # @param help [String]
32
32
  # @yield [*Array, **Hash]
33
- def task(name, help = "", &block)
33
+ def task(name, help = nil, &block)
34
34
  if !name.is_a?(Symbol)
35
35
  puts
36
36
  puts "First task parameter must be a symbol".red
37
37
  exit 6
38
38
  end
39
- if !help.is_a?(String)
39
+ if !help.nil? && !help.is_a?(String)
40
40
  puts
41
41
  puts "Second task parameter must be a string".red
42
42
  exit 6
43
43
  end
44
+ if help.nil?
45
+ 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?
49
+ end
44
50
  @tasks.store(
45
51
  name,
46
52
  {
47
- :help => Markdown::Engine.new(help).to_ansi,
53
+ :help => help.nil? ? "" : Markdown::Engine.new(help).to_ansi,
48
54
  :block => block
49
55
  }
50
56
  )
@@ -55,7 +61,11 @@ end
55
61
  # @param options [Hash] Optional options sent to the task.
56
62
  def run(task_name_or_command, *arguments, **options)
57
63
  if task_name_or_command.is_a?(Symbol)
58
- @tasks[task_name_or_command][:block].call *arguments, **options
64
+ if options.empty?
65
+ @tasks[task_name_or_command][:block].call *arguments
66
+ else
67
+ @tasks[task_name_or_command][:block].call *arguments, **options
68
+ end
59
69
  return
60
70
  end
61
71
 
@@ -76,6 +86,12 @@ def run(task_name_or_command, *arguments, **options)
76
86
  puts
77
87
  end
78
88
 
89
+ def are_you_sure?(text = "Are you sure?")
90
+ puts "#{text.yellow.bold} [yN]"
91
+ answer = STDIN.gets.chomp.downcase.chars.first
92
+ exit 9 unless answer == "y"
93
+ end
94
+
79
95
  # @param uri [String]
80
96
  def require_remote(uri)
81
97
  cache_path = "/tmp/run_cache_#{Digest::MD5.hexdigest(uri)}"
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Delogu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-22 00:00:00.000000000 Z
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email: aurelien.delogu@gmail.com
15
15
  executables:
16
16
  - run
@@ -29,7 +29,7 @@ homepage: https://github.com/pyrsmk/run
29
29
  licenses:
30
30
  - MIT
31
31
  metadata: {}
32
- post_install_message:
32
+ post_install_message:
33
33
  rdoc_options: []
34
34
  require_paths:
35
35
  - lib
@@ -44,9 +44,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubyforge_project:
47
+ rubyforge_project:
48
48
  rubygems_version: 2.5.2
49
- signing_key:
49
+ signing_key:
50
50
  specification_version: 4
51
51
  summary: Run project tasks with ease
52
52
  test_files: []