/
gt
executable file
·66 lines (51 loc) · 1.33 KB
/
gt
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
61
62
63
64
65
66
#!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'growl-transfer'
require 'optparse'
require 'pp'
require 'readline'
require 'highline/import'
# Get source and destintation from command line
version = File.exist?('VERSION') ? File.read('VERSION') : ""
help =<<HELP
Growl-Transfer version #{version}
Basic Command Line Usage:
gt you@server.com:/file/path local/path # Downloads /file/path to local/path
Options:
HELP
options = {}
OptionParser.new do |opts|
opts.banner = help
opts.on("-v", "--[no-]verbose", "Run Verbosely") do |v|
options[:verbose] = v
end
opts.on("--version", "Display current version") do
puts "Growl-Transfer " + version
exit 0
end
opts.on('-p', '--password', 'Use this password') do |v|
options[:password] = true
end
end.parse!
case ARGV.size
when 1
options[:remote] = ARGV[0]
options[:local] = '.'
when 2
options[:remote] = ARGV[0]
options[:local] = ARGV[1]
else
puts "Invalid options: run gt --help for usage"
exit(1)
end
def get_password(prompt="Enter Password")
ask(prompt) {|q| q.echo = false}
end
if options[:password]
options[:password] = get_password()
if options[:password].empty?
puts 'Failed to enter password'
exit(1)
end
end
GrowlTransfer::Download(options)