From e552802051434f54d8555344c96b81ecb7648706 Mon Sep 17 00:00:00 2001 From: Hugo Wetterberg Date: Wed, 12 Oct 2011 09:38:20 +0200 Subject: [PATCH] Added support to cloudapp for uploading stdin. --- plugins/cloudapp/cloudapp.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/cloudapp/cloudapp.rb b/plugins/cloudapp/cloudapp.rb index a11cfdb32..798688305 100755 --- a/plugins/cloudapp/cloudapp.rb +++ b/plugins/cloudapp/cloudapp.rb @@ -45,16 +45,28 @@ end if ARGV[0].nil? puts "You need to specify a file to upload." exit!(1) +elsif ARGV[0] == '-' + if ARGV[1].nil? + puts "You need to specify a filename for the input stream." + puts "Example usage: echo \"Hello\" | cloudapp - hello.txt" + exit!(1) + end + file = "/tmp/#{ARGV[1]}" + f = open(file, File::CREAT | File::WRONLY | File::BINARY) + f.write STDIN.read + f.close +else + file = ARGV[0] end CloudApp.authenticate(email,password) -url = CloudApp::Item.create(:upload, {:file => ARGV[0]}).url +url = CloudApp::Item.create(:upload, {:file => file}).url # Say it for good measure. puts "Uploaded to #{url}." # Get the embed link. -url = "#{url}/#{ARGV[0].split('/').last}" +url = "#{url}/#{file.split('/').last}" # Copy it to your (Mac's) clipboard. `echo '#{url}' | tr -d "\n" | pbcopy`