command_timer 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,13 @@ module CommandTimer
4
4
  attr_accessor :description
5
5
  attr_accessor :content
6
6
  attr_accessor :observer
7
+ attr_accessor :grep
7
8
 
8
9
  def burn_time
9
10
  if @burn_time =~ /[0-9]{2}:[0-9]{2}:[0-9]{2}/
10
11
  CommandTimer.parse_time(@burn_time)
11
12
  else
12
- nil
13
+ @burn_time
13
14
  end
14
15
  end
15
16
 
@@ -17,26 +18,53 @@ module CommandTimer
17
18
  echo_command
18
19
  system @content
19
20
  if @observer
20
- puts "===================="
21
- puts "= Start observer, input S to stop it."
22
- puts "= #{@observer}"
23
- puts "===================="
24
- thread = Thread.new do
21
+ run_observer
22
+ end
23
+ end
24
+
25
+ def echo_command
26
+ @content.split(';').each do |line|
27
+ puts ">> #{line.strip.gsub('\\', '')}"
28
+ end
29
+ end
30
+
31
+ def run_observer
32
+ puts "===================="
33
+ puts "= Start observer, input S to stop it."
34
+ puts "= #{@observer}"
35
+ puts "===================="
36
+ observer_thread = Thread.new do
37
+ if @grep
38
+ run_grep
39
+ else
25
40
  system @observer
26
41
  end
27
- thread.run
42
+ end
43
+ observer_thread.run
44
+ interaction_thread = Thread.new do
28
45
  input = ""
29
46
  until ["s", "S", "stop"].include?(input) do
30
47
  input = STDIN.gets.chomp
31
48
  end
32
- thread.kill
33
- puts "Observer stopped."
34
49
  end
50
+ interaction_thread.run
51
+ while observer_thread.alive? and interaction_thread.alive? do
52
+ end
53
+ observer_thread.kill
54
+ interaction_thread.kill
55
+ puts "Observer stopped."
35
56
  end
36
57
 
37
- def echo_command
38
- @content.split(';').each do |line|
39
- puts ">> #{line.strip.gsub('\\', '')}"
58
+ def run_grep
59
+ current_count = 0
60
+ grep_str = @grep.split(",").first
61
+ end_count = @grep.split(",").last.to_i
62
+ IO.popen @observer do |f|
63
+ while line = f.gets
64
+ puts line
65
+ current_count += 1 if line.include?(grep_str)
66
+ break if current_count >= end_count
67
+ end
40
68
  end
41
69
  end
42
70
  end
@@ -14,7 +14,11 @@ module CommandTimer
14
14
  puts "# #{command.description}" if command.description
15
15
  puts "####################"
16
16
  if command.burn_time
17
- count_down_and_burn_command(command)
17
+ if ['auto', 'Auto'].include?(command.burn_time)
18
+ command.exec
19
+ else
20
+ count_down_and_burn_command(command)
21
+ end
18
22
  else
19
23
  wait_input_to_continue(command)
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module CommandTimer
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-12 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple tool to execute commands on schedule
15
15
  email: