-
Notifications
You must be signed in to change notification settings - Fork 0
/
whatthecommit
executable file
·60 lines (49 loc) · 1.5 KB
/
whatthecommit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
class WhatTheCommit
VERSION = "0.9.3"
CMD = File.basename($0)
URL = "http://whatthecommit.com/"
DISCLAIMER = " (courtesy of #{URL})"
def usage(exit_code = 0)
puts "Usage: #{CMD} [-n, -o]"
puts
puts "Scrapes random commit messages from #{URL}, "
puts "useful for the daily: git commit -am \"$(#{CMD})\""
puts
puts "Options:"
puts " -n, --no-disclaimer do not append disclaimer"
puts " -o, --open open #{URL} in your browser (MacOS X only)"
puts
puts " -v, --version show version information and exit"
puts " -h, --help display this usage and exit"
puts
exit(exit_code)
end
def version
puts "#{CMD} (#{VERSION}) - random commit message generator (#{URL})"
exit 0
end
def error(msg)
STDERR.puts "#{CMD}: [error] #{msg}"
usage(1)
end
def launch_browser; exec "open '#{URL}'" end
def print_random_message
require 'open-uri'
puts open(URL).select { |e| e =~ /^<p>/ }.first.gsub(/^<p>/, "").gsub("\n", "")# + (@show_disclaimer ? DISCLAIMER : '')
end
def run(*args)
@show_disclaimer = true
case args.first
when '--help', '-h' then usage
when '--version', '-v' then version
when '--open', '-o' then launch_browser
when '--no-disclaimer', '-n'
@show_disclaimer = false
else
error("unknown option(s): #{args.first}") unless args.empty?
end
print_random_message
end
end
WhatTheCommit.new.run(*ARGV)