bin/filentory-cli in filentory-cli-0.2.0 vs bin/filentory-cli in filentory-cli-0.3.0

- old
+ new

@@ -1,40 +1,66 @@ #!/usr/bin/env ruby - +require 'yaml' require 'optparse' require 'methadone' require 'filentory.rb' +#require 'filentory/sender.rb' +#require 'uri' class App include Methadone::Main include Methadone::CLILogging main do |name, path, server| # Add args you want: |like,so| absolute_path = File.expand_path(path) info("name: #{name}") info "path: #{absolute_path}" info "server: #{server}" - info "type: #{options[:type]}" + info "mediatype: #{options[:type]}" data_store = Datastore.new (name) - data_store.type = options[:type] + data_store.mediatype = options[:type] collector = Collector.new data_store.files << collector.collect(absolute_path) + + begin + if server.nil? + puts data_store.to_json + else - puts data_store.to_json - # your program code here - # You can access CLI options via - # the options Hash + begin + config_path = options[:auth] || File.join(ENV['HOME'], '.filentory.yaml') + auth_data = YAML.load_file(config_path) + auth_data.keys.each {|key| puts "will send #{key}"} + rescue + auth_data = nil + end + + sender = Sender.new(server) + sender.additional_fields = auth_data + response = sender.post(data_store.to_json) + + if(sender.failed?) + puts "ERROR: sending to '#{server}' failed: #{response.code} - #{response.message}" + else + puts "Sending '#{name}' to '#{server}' was successfull." + end + end + + rescue => exeption_detected + puts "Error: #{exeption_detected}" + end end # supplemental methods here # Declare command-line interface here description "A tool to create an filentory-cli of a storage medium" # Options: on("-t TYPE", "--type TYPE", "The type of the media to add to the filentory-cli") + on("-a FILE", "--auth FILE", "A path to a YAML file with authentication information") # Arguments of Filentory-cli arg :name # required argument arg :path arg :server, :optional # optional argument