Class: Morpheus::Cli::Logout

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/logout.rb

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, included

Constructor Details

#initialize ⇒ Logout

include Morpheus::Cli::WhoamiHelper include Morpheus::Cli::AccountsHelper



15
16
17
# File 'lib/morpheus/cli/logout.rb', line 15

def initialize() 
	@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end

Instance Method Details

#connect(opts) ⇒ Object



19
20
21
22
# File 'lib/morpheus/cli/logout.rb', line 19

def connect(opts)
	#@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
	#@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
end

#handle(args) ⇒ Object



28
29
30
# File 'lib/morpheus/cli/logout.rb', line 28

def handle(args)
	logout(args)
end

#logout(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/morpheus/cli/logout.rb', line 32

def logout(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, []) # todo: support :remote too perhaps
	end
	optparse.parse(args)

	connect(options)

	begin

		creds = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
		if !creds
			print yellow,"\nYou are not logged in to #{@appliance_name} - #{@appliance_url}.\n\n",reset
			# exit 0
		else
			Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).logout()
		end

	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end

end

#usage ⇒ Object



24
25
26
# File 'lib/morpheus/cli/logout.rb', line 24

def usage
	"Usage: morpheus login"
end