Sha256: 5b66c8875fb942e872bfbfc4ba8aa09194727d9b0f373ee1a0e01e4d77dc6afb

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

require 'thor'
require 'yaml'

module Rmd
  class FileNotFound < StandardError; end

  class Cli < Thor
    CONFIG_PATH = './creds.yml'

    include Thor::Actions

    class << self
      def load_config
        fail(FileNotFound, 'Creds file not found. Ask DucLe for it') unless File.file?(CONFIG_PATH)
        config = YAML.load_file(File.expand_path(CONFIG_PATH))
        Configure.set(config)
      end
    end

    desc 'deploy', 'Deploy to a server'
    method_option :server, aliases: '-s', desc: 'Server name', type: :string, required: true
    def deploy
      Cli.load_config
      DeployService.deploy(options[:server])
    rescue Exception => e
      $stdout.puts(e.message)
    end

    desc 'restart', 'Restart a server. Please note that the latest image will be pulled to deploy to servers'
    method_option :server, aliases: '-s', desc: 'Server name', type: :string, required: true
    def restart
      Cli.load_config
      DeployService.restart(options[:server])
    rescue Exception => e
      $stdout.puts(e.message)
    end

    desc 'logs', 'Logs of servers'
    method_option :server, aliases: '-s', desc: 'Server name', type: :string, required: true
    def logs
      Cli.load_config
      DeployService.logs(options[:server])
    rescue Exception => e
      $stdout.puts(e.message)
    end

    desc 'nginx', 'Logs of the nginx server'
    method_option :server, aliases: '-s', desc: 'Server name', type: :string, required: true
    method_option :type, aliases: '-t', desc: "Type of log: #{TYPE}", type: :string, required: true
    def nginx
      Cli.load_config
      DeployService.nginx(options[:server], options[:type])
    rescue Exception => e
      $stdout.puts(e.message)
    end

    desc 'bash', 'Bash of servers'
    method_option :server, aliases: '-s', desc: 'Server name', type: :string, required: true
    def bash
      Cli.load_config
      DeployService.bash(options[:server])
    rescue Exception => e
      $stdout.puts(e.message)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rmdd-0.1.11 lib/rmd/cli.rb
rmdd-0.1.10 lib/rmd/cli.rb
rmdd-0.1.9 lib/rmd/cli.rb