Sha256: a165c988667cf0b93031bcb7ffa5c54dc4d01cde3f39dd0a4a1e0eb454fbb637

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

require 'tty-spinner'
require 'yaml'
require 'tty-table'
require 'zip'
require 'colorize'
require 'faastruby/cli/commands'
require 'faastruby/cli/package'

module FaaStRuby
  FAASTRUBY_YAML = 'faastruby.yml'
  SPINNER_FORMAT = :spin_2
  SUPPORTED_RUNTIMES = ['ruby:2.5.3', 'ruby:2.6.0', 'crystal:0.27.0']
  class CLI
    def self.error(message, color: :red)
      message.each {|m| STDERR.puts m.colorize(color)} if message.is_a?(Array)
      STDERR.puts message.colorize(color) if message.is_a?(String)
      exit 1
    end

    def self.run(command, args)
      if command.nil?
        FaaStRuby::Command::Help.new(args).run
        return
      end
      start_server(args) if command == 'server'
      check_version
      check_region
      error("Unknown command: #{command}") unless FaaStRuby::Command::COMMANDS.has_key?(command)
      FaaStRuby::Command::COMMANDS[command].new(args).run
    end

    def self.check_version
      latest = RestClient.get('https://faastruby.io/gem/minimum.txt').body rescue '0.0.1'
      if Gem::Version.new(FaaStRuby::VERSION) < Gem::Version.new(latest)
        FaaStRuby.error([
          "You are using an old version of the gem. Please run 'gem update faastruby'.".red,
          "Installed version: #{FaaStRuby::VERSION}",
          "Latest version: #{latest}"
        ], color: nil)
      end
    end

    def self.check_region
      ENV['FAASTRUBY_REGION'] ||= DEFAULT_REGION
      error(["No such region: #{ENV['FAASTRUBY_REGION']}".red, "Valid regions are:  #{FaaStRuby::REGIONS.join(' | ')}"], color: nil) unless FaaStRuby::REGIONS.include?(ENV['FAASTRUBY_REGION'])
    end

    def self.start_server(args)
      exec("faastruby-server #{args.join(' ')}")
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
faastruby-0.4.14 lib/faastruby/cli.rb
faastruby-0.4.12 lib/faastruby/cli.rb
faastruby-0.4.11 lib/faastruby/cli.rb
faastruby-0.4.10 lib/faastruby/cli.rb
faastruby-0.4.9 lib/faastruby/cli.rb
faastruby-0.4.8 lib/faastruby/cli.rb
faastruby-0.4.7 lib/faastruby/cli.rb
faastruby-0.4.6 lib/faastruby/cli.rb
faastruby-0.4.5 lib/faastruby/cli.rb
faastruby-0.4.4 lib/faastruby/cli.rb
faastruby-0.4.3 lib/faastruby/cli.rb
faastruby-0.4.2 lib/faastruby/cli.rb
faastruby-0.4.1 lib/faastruby/cli.rb
faastruby-0.4.0 lib/faastruby/cli.rb
faastruby-0.3.8 lib/faastruby/cli.rb
faastruby-0.3.7 lib/faastruby/cli.rb