From ca02796551a2d85241e065a66a9cc1c5f3a8d68c Mon Sep 17 00:00:00 2001 From: Peter Haza Date: Tue, 29 Nov 2011 20:28:30 +0100 Subject: [PATCH] Ability to give a file as first argument to haste-client This patch makes it possible to either pipe data into the haste client, or just give a filename as first argument. Signed-off-by: Peter Haza --- lib/haste.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/haste.rb b/lib/haste.rb index 2b23011..6125693 100644 --- a/lib/haste.rb +++ b/lib/haste.rb @@ -12,8 +12,20 @@ module Haste # Pull all of the data from STDIN def initialize - @input = STDIN.readlines.join - @input.strip! + if STDIN.tty? + if ARGV.empty? + puts "No input file given" + exit + end + + file = ARGV[0] + abort "#{file} doesn't exist" unless File.exists?(file) + + @input = open(file).read.strip + else + @input = STDIN.readlines.join + @input.strip! + end end # Upload the and output the URL we get back