From da532a6b64fa35b8b7d6aac53e3683ea14a2b19f Mon Sep 17 00:00:00 2001 From: Aaron Morey Date: Mon, 29 Nov 2010 19:22:33 -0600 Subject: [PATCH] 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 --- bin/noprocrast | 13 ++++++++++++- lib/noprocrast.rb | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bin/noprocrast b/bin/noprocrast index 40fad04..99b3557 100644 --- a/bin/noprocrast +++ b/bin/noprocrast @@ -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" diff --git a/lib/noprocrast.rb b/lib/noprocrast.rb index 5237bfe..e6fa219 100644 --- a/lib/noprocrast.rb +++ b/lib/noprocrast.rb @@ -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