after 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/bin/after +1 -21
  3. data/lib/after.rb +37 -12
  4. data/spec/spec.after.rb +14 -9
  5. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/bin/after CHANGED
@@ -8,24 +8,4 @@ end
8
8
  require 'after'
9
9
  require 'andand' # to avoid warnings
10
10
 
11
- if ARGV[0] == '-v'
12
- ARGV.shift
13
- $VERBOSE = true
14
- puts 'running in verbose mode'
15
- end
16
-
17
- if ARGV[0] == '-l' || ARGV[0] == '--list'
18
- $VERBOSE = true # so it'll output the names...
19
- ARGV.shift
20
- After.find_pids(ARGV.shift)
21
- exit # premature exit
22
- elsif ARGV[0] == '-p'
23
- ARGV.shift
24
- pid = ARGV.shift
25
- After.wait_pid pid.to_i
26
- else
27
- After.find_and_wait_for(ARGV.shift)
28
- end
29
-
30
- puts 'running', ARGV if $VERBOSE
31
- system(*ARGV) if ARGV.length > 0
11
+ After.go
data/lib/after.rb CHANGED
@@ -12,9 +12,9 @@ class After
12
12
  if (proc.CommandLine && proc.CommandLine.contain?(many_args)) || proc.Name.include?(many_args)
13
13
  pid = proc.ProcessId.to_i
14
14
  next if pid == Process.pid
15
- pids << pid
15
+ pids << [pid, proc.CommandLine]
16
16
  if $VERBOSE
17
- print 'adding ', proc.ProcessId, ' ', proc.Name, ' ', proc.CommandLine, "\n"
17
+ print 'adding ', proc.ProcessId, ' ', proc.Name, ' ', proc.CommandLine, "\n"
18
18
  end
19
19
  end
20
20
  end
@@ -22,18 +22,43 @@ class After
22
22
  end
23
23
 
24
24
  def self.find_and_wait_for(args)
25
- pids = find_pids args
26
- if pids.length > 1
27
- puts "found more than one -- waiting for all #{pids.inspect}"
28
- end
29
- pids.each{|pid|
30
- puts "waiting for #{pid}"
31
- WaitPid.wait_nonchild_pid pid
32
- }
25
+ pids = find_pids args
26
+ if pids.length > 1
27
+ puts "found more than one -- waiting for all #{pids.map{|pid, name| name}.inspect}"
28
+ end
29
+ pids.each{|pid, name|
30
+ puts "waiting for #{pid} (#{name})"
31
+ WaitPid.wait_nonchild_pid pid
32
+ }
33
33
  end
34
-
34
+
35
35
  def self.wait_pid pid
36
36
  WaitPid.wait_nonchild_pid pid
37
37
  end
38
38
 
39
- end
39
+ # main, really
40
+ def self.go
41
+ if ARGV[0] == '-v'
42
+ ARGV.shift
43
+ $VERBOSE = true
44
+ puts 'running in verbose mode'
45
+ end
46
+
47
+ if ARGV[0] == '-l' || ARGV[0] == '--list'
48
+ $VERBOSE = true # so it'll output the names...
49
+ ARGV.shift
50
+ After.find_pids(ARGV.shift)
51
+ exit # premature exit
52
+ elsif ARGV[0] == '-p'
53
+ ARGV.shift
54
+ pid = ARGV.shift
55
+ After.wait_pid pid.to_i
56
+ else
57
+ After.find_and_wait_for(ARGV.shift)
58
+ end
59
+
60
+ puts 'running', ARGV if $VERBOSE
61
+ system(*ARGV) if ARGV.length > 0
62
+ end
63
+
64
+ end
data/spec/spec.after.rb CHANGED
@@ -13,7 +13,7 @@ describe After do
13
13
  it "should be able to grab the right pid" do
14
14
  pid = go
15
15
  a = After.find_pids('sleep')
16
- a[0].should == pid
16
+ a[0][0].should == pid
17
17
  end
18
18
 
19
19
  it "should immediately return if the other process doesn't exist" do
@@ -39,12 +39,12 @@ describe After do
39
39
 
40
40
  it "should not return the PID of this process" do
41
41
  a = After.find_pids('ruby')
42
- assert !Process.pid.in?(a)
42
+ assert !Process.pid.in?(a.map_by(:first))
43
43
  end
44
44
 
45
45
  it "should allow for passing in a pid" do
46
46
  pid = go 1
47
- After.wait_pid pid
47
+ After.wait_pid pid
48
48
  end
49
49
 
50
50
  it "should find .bat filenames" do
@@ -52,16 +52,19 @@ describe After do
52
52
  pid = Process.spawn "cmd /c sleep.bat 1"
53
53
  Thread.new { Process.wait pid } # wait for it, so we can collect child processes, too
54
54
  a = After.find_pids('sleep.bat')
55
- assert a == [pid]
55
+ assert a[0][0] == pid && a.length == 1
56
56
  end
57
57
 
58
58
 
59
59
  it "should find .bat filenames when run by selves" do
60
- # unfortunately I don't know how to query for exact parameters, though...
61
- pid = Process.spawn "sleep.bat 1"
62
- Thread.new { Process.wait pid } # wait for it, so we can collect child processes, too
63
- a = After.find_pids('sleep.bat')
64
- assert a == [pid]
60
+ pending "knowing how to do this in windows" do
61
+
62
+ # unfortunately I don't know how to query for exact parameters, though...
63
+ pid = Process.spawn "sleep.bat 1"
64
+ Thread.new { Process.wait pid } # wait for it, so we can collect child processes, too
65
+ a = After.find_pids('sleep.bat')
66
+ assert a[0][0] == pid && a.length == 1
67
+ end
65
68
  end
66
69
 
67
70
  it "should find exe names too" do
@@ -70,5 +73,7 @@ describe After do
70
73
  end
71
74
 
72
75
  it "should split the commands up right and across name, too"
76
+
77
+
73
78
 
74
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rogerdpack
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-07 00:00:00 -07:00
12
+ date: 2010-01-08 00:00:00 -07:00
13
13
  default_executable: after
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency