supervise 1.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 (2) hide show
  1. data/bin/supervise +102 -0
  2. metadata +79 -0
data/bin/supervise ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'rainbow'
5
+ require 'trollop'
6
+ require 'open3'
7
+
8
+ VERSION = '1.0'
9
+
10
+ app = File.basename(__FILE__)
11
+
12
+
13
+ p = Trollop::Parser.new do
14
+ version "#{__FILE__} #{VERSION}"
15
+
16
+ banner <<-EOS
17
+ #{app.upcase} ensures that all your commands are well exectued.
18
+
19
+ Usage:
20
+
21
+ #{app} [options] <filename>
22
+ cat <filename> | #{app} [options]
23
+
24
+ where [options] are:
25
+
26
+ EOS
27
+
28
+ opt :retry, 'Retry this number of times before giving up', :default => 3
29
+ opt :retry_delay, '<seconds>', :default => 0, :short => :d
30
+ opt :verbose
31
+ end
32
+
33
+ commands = []
34
+
35
+ @opts = Trollop::with_standard_exception_handling p do
36
+
37
+ raise Trollop::HelpNeeded if ARGV.empty? and STDIN.tty?
38
+
39
+ commands = STDIN
40
+
41
+ if ARGV.size == 1
42
+ input = ARGV.first
43
+ begin
44
+ commands = IO.readlines(ARGV.first)
45
+ rescue
46
+ abort "No such file #{input}."
47
+ end
48
+ end
49
+
50
+ p.parse ARGV
51
+
52
+ end
53
+
54
+ aborted_commands = []
55
+ STDOUT.sync = true
56
+
57
+ num_commands = 0
58
+ num_success = 0
59
+
60
+ commands.each do |cmd|
61
+
62
+ cmd.chomp!
63
+
64
+ next if cmd.strip.empty?
65
+
66
+ num_commands += 1
67
+
68
+ tries = 0
69
+ begin
70
+
71
+ tries += 1
72
+ Open3.capture2e(cmd)
73
+
74
+ if $?
75
+ num_success += 1
76
+ print '✔'.color(:green)
77
+ else
78
+ raise
79
+ end
80
+
81
+ rescue
82
+
83
+ print '•'.color(:red)
84
+
85
+ if tries < @opts[:retry]
86
+ sleep @opts[:retry_delay]
87
+ retry
88
+ else
89
+ print '✘'.color(:red)
90
+ aborted_commands << cmd
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ puts
98
+
99
+ if not aborted_commands.empty?
100
+ warn "I supervised #{num_commands} commands, with #{@opts[:retry]} opportunities each, passed #{num_success} and given up #{aborted_commands.size}. The given ups are saved in supervise.log."
101
+ File.open('supervise.log', 'w') {|f| f.puts aborted_commands.map {|line| " #{line}" }.join("\n") }
102
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: supervise
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guangnan Cheng
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: trollop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Visualize commands exit status and report the given up commands on the
47
+ end.
48
+ email: me@chengguangnan.com
49
+ executables:
50
+ - supervise
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - bin/supervise
55
+ homepage: https://github.com/guangnan/supervise
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.23
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Observe shell commands exit status and retry.
79
+ test_files: []