Class: Gphotos::App
- Inherits:
-
Object
- Object
- Gphotos::App
- Defined in:
- lib/gphotos/app.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ App
Returns a new instance of App.
65 66 67 68 69 |
# File 'lib/gphotos/app.rb', line 65 def initialize(args) = self.class.parse(args) config = self.class.load_config('~/.gphotos/config.yml') @options = OpenStruct.new(config.merge(.to_h)) end |
Class Method Details
.load_config(file) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/gphotos/app.rb', line 56 def self.load_config(file) full_path = File.(file) if File.exists?(full_path) YAML.load_file(full_path) else {} end end |
.parse(args) ⇒ Object
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 |
# File 'lib/gphotos/app.rb', line 9 def self.parse(args) = OpenStruct.new opt_parser = OptionParser.new do |opts| opts. = "Usage: #{$0} [options] file..." opts.separator "\nSpecific options:" opts.on("-eEMAIL", "--email=EMAIL", "Set email to EMAIL") do |o| .email = o end opts.on("-pPASSWD", "--passwd=PASSWD", "Set passwd to PASSWD") do |o| .passwd = o end opts.on("-lFILE", "--list=FILE", "Read list of files to upload from FILE") do |o| .list = o end opts.separator "\nCommon options:" opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end opts.on_tail('-V', '--version', 'Show version') do puts VERSION exit end end begin opt_parser.parse!(args) rescue OptionParser::InvalidOption puts opt_parser exit end if args.size == 0 and !.list puts opt_parser exit end end |
Instance Method Details
#run ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gphotos/app.rb', line 71 def run files = [] files.concat(ARGV) if @options.list files.concat(open(@options.list).read.split("\n")) end gphotos = Gphotos.new(@options.email, @options.passwd, @options.passwd_exec) puts "upload(#{files.size}):" uploaded, skipped, not_exist = gphotos.upload(files) do |file, status| case status when :uploading print "#{file} ..." when :skipped, :not_exist puts "\b\b\b(#{status})" when :uploaded puts "\b\b\b " end end if skipped.size > 0 puts puts 'skipped:' puts skipped.join("\n") end if not_exist.size > 0 puts puts 'not_exist:' puts not_exist.join("\n") end puts puts 'done:' puts "#{uploaded.size} uploaded" puts "#{skipped.size} skipped" if skipped.size > 0 puts "#{not_exist.size} not exist" if not_exist.size > 0 gphotos.quit end |