#!/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 "mediatype: #{options[:type]}" data_store = Datastore.new (name) 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 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 # # # Make an argument optional # arg :optional_arg, :optional version Filentory::VERSION use_log_level_option go! end