Sha256: f97967f85fdcd4e3f19aa65bd33e8d80f05f213a470a5ba4f14745e14970470b

Contents?: true

Size: 1.72 KB

Versions: 59

Compression:

Stored size: 1.72 KB

Contents

require "shelly/cli/command"
require "time"

module Shelly
  module CLI
    class Database < Command
      namespace :database
      include Helpers
      before_hook :logged_in?, :only => [:reset, :tunnel]
      class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"

      desc "reset KIND", "Reset database"
      long_desc %{
        Removes all objects from the database
        KIND - Database kind. Possible values are: postgresql or mongodb
      }
      def reset(kind)
        app = multiple_clouds(options[:cloud], "database reset")
        say "You are about to reset database #{kind} for cloud #{app}"
        say "All database objects and data will be removed"
        ask_to_reset_database
        app.reset_database(kind)
      rescue Client::ConflictException
        say_error "Cloud #{app} wasn't deployed properly. Cannot reset database."
      end

      desc "tunnel KIND", "Setup tunnel to given database"
      method_option :port, :type => :string, :aliases => "-p",
        :desc => "Local port on which tunnel will be set up"
      def tunnel(kind)
        app = multiple_clouds(options[:cloud], "database tunnel")
        local_port = options[:port] || 9900
        conn = app.tunnel_connection(kind)
        say "Connection details", :green
        say "host:     localhost"
        say "port:     #{local_port}"
        say "database: #{conn['service']['database_name']}"
        say "username: #{conn['service']['username']}"
        say "password: #{conn['service']['password']}"
        app.setup_tunnel(conn, local_port)
      rescue Client::NotFoundException => e
        say_error e["message"]
      rescue Client::ConflictException => e
        say_error e["message"]
      end
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
shelly-0.5.7 lib/shelly/cli/database.rb
shelly-0.5.6 lib/shelly/cli/database.rb
shelly-0.5.5 lib/shelly/cli/database.rb
shelly-0.5.4 lib/shelly/cli/database.rb
shelly-0.5.3 lib/shelly/cli/database.rb
shelly-0.5.2 lib/shelly/cli/database.rb
shelly-0.5.1 lib/shelly/cli/database.rb
shelly-0.5.0 lib/shelly/cli/database.rb
shelly-0.4.42 lib/shelly/cli/database.rb
shelly-0.4.41 lib/shelly/cli/database.rb
shelly-0.4.40 lib/shelly/cli/database.rb
shelly-0.4.39 lib/shelly/cli/database.rb
shelly-0.4.38 lib/shelly/cli/database.rb
shelly-0.4.37 lib/shelly/cli/database.rb
shelly-0.4.36 lib/shelly/cli/database.rb
shelly-0.4.35 lib/shelly/cli/database.rb
shelly-0.4.34 lib/shelly/cli/database.rb
shelly-0.4.33 lib/shelly/cli/database.rb
shelly-0.4.32 lib/shelly/cli/database.rb
shelly-0.4.31 lib/shelly/cli/database.rb