First commit to cloned copy of noprocrast 1.6

bin/noprocrast
  - Cleaned up error messages
  - Print error when giving invalid or too many inputs

lib/noprocrast.rb
  - Added entries with "www." prefix for hosts without it already specified
This commit is contained in:
Aaron Morey 2010-11-29 19:22:33 -06:00
parent f28ac5100d
commit da532a6b64
2 changed files with 15 additions and 2 deletions

View File

@ -2,6 +2,15 @@
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'noprocrast')
acceptable = "[on|off|status|edit]"
message = "Usage: [sudo] noprocrast #{acceptable}"
# Bail immediately if inputs are wrong
if ARGV.length > 1 then
puts message
exit
end
begin
case ARGV.first
when 'on', 'reload'
@ -22,7 +31,9 @@ begin
puts "Saved. Now: noprocrast on"
end
when 'help', '-h', '--help', nil
puts "Usage: [sudo] noprocrast [on|off|status|edit]"
puts message
else
puts "Error: bad input.\n#{message}"
end
rescue Errno::EACCES
puts "Permission denied: try sudo noprocrast"

View File

@ -12,7 +12,9 @@ class Noprocrast
def current_hosts
setup_deny_file_if_required!
File.read(deny_file_path).split(/\n/).select { |line| line.match(/[a-zA-Z0-9]/) }.map(&:strip)
hosts = File.read(deny_file_path).split(/\n/).select { |line| line.match(/[a-zA-Z0-9]/) }.map(&:strip)
wwwhosts = hosts.map { |h| "www." + h.to_s unless h =~ /^www/ }
(hosts + wwwhosts).sort
end
def hosts_file_content