Sha256: 67f2d415fa45045656683ca2694a8f35c0fefbd3837f0d6688ed9a4f3b764ebe
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
#!/usr/bin/env ruby # Commandline client for controlling morph and running scrapers and things require "thor" require "rest_client" # TODO Do compression on the tar file #require 'zlib' require 'archive/tar/minitar' require 'pathname' require 'json' require 'morph-cli' class MorphThor < Thor class_option :dev, default: false, type: :boolean, desc: "Run against a local dev of Morph" desc "[execute]", "execute morph scraper" option :directory, :default => Dir.getwd def execute config = MorphCLI.load_config if options[:dev] env_config = config[:development] else env_config = config[:production] end config = ask_and_save_api_key(env_config, config) if env_config[:api_key].nil? api_key_is_valid = false until api_key_is_valid begin MorphCLI.execute(options[:directory], options[:dev], env_config) api_key_is_valid = true rescue RestClient::Unauthorized puts "Your key isn't working. Let's try again." config = ask_and_save_api_key(env_config, config) rescue Errno::ECONNREFUSED => e $stderr.puts "Morph doesn't look to be running at #{env_config[:base_url]} (#{e})" exit(1) rescue RestClient::InternalServerError => e $stderr.puts "Uh oh. Something has gone wrong on the Morph server at #{env_config[:base_url]} (#{e})" exit(1) end end end no_commands { def ask_and_save_api_key(env_config, config) env_config[:api_key] = ask("What is your key? (Go to #{env_config[:base_url]}/settings)") MorphCLI.save_config(config) config end } end # If morph is run without any parameters it's the same as "morph execute" MorphThor.start(ARGV.empty? ? ["execute"] : ARGV)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
morph-cli-0.1.1 | bin/morph |
morph-cli-0.1 | bin/morph |
morph-cli-0.0.2 | bin/morph |