Module: Ompload::CLI

Extended by:
CLI, Shell
Included in:
CLI
Defined in:
lib/ompload.rb

Instance Method Summary collapse

Methods included from Shell

curl_installed?, piped_data_given?, xclip_installed?

Instance Method Details

#run(argv, options = {}) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ompload.rb', line 185

def run(argv, options = {})
  unless curl_installed?
    abort('error: curl missing or not in path. Cannot continue.')
  end

  if options[:version]
    puts VERSION
    exit
  end

  abort(USAGE) if ARGV.size < 1 && !piped_data_given? || options[:help]

  UploadsHandler.handle_files(ARGV, options)
  UploadsHandler.handle_data(STDIN.read(), options) if piped_data_given?

  if xclip_installed? && options[:clip] && !XclipBuffer.instance.content.empty?
    IO.popen('xclip', 'w+').puts XclipBuffer.instance.content
  end

  if !options[:quiet] && !options[:url]
    if ErrorCounter.instance.count > 0
      puts "Finished with #{ErrorCounter.instance.count} errors."
    else
      puts 'Success.'
    end
  end
end