41 lines
988 B
Ruby
41 lines
988 B
Ruby
require "devops-client/handler/handler"
|
|
require "devops-client/options/provider_options"
|
|
require "devops-client/output/provider"
|
|
|
|
class Provider < Handler
|
|
|
|
output_with Output::Provider
|
|
|
|
def initialize(host, def_options={})
|
|
@host, @options = host, def_options
|
|
@options_parser = ProviderOptions.new(ARGV, def_options)
|
|
end
|
|
|
|
def handle
|
|
@options, @args = @options_parser.parse_options_for!(current_command)
|
|
case current_command
|
|
when :list
|
|
list_handler
|
|
output(output_type: :list)
|
|
when :accounts
|
|
@provider = @args[2]
|
|
accounts_handler
|
|
output(output_type: :accounts, provider: @provider)
|
|
end
|
|
end
|
|
|
|
def list_handler
|
|
@list = get("/providers").sort!{|x,y| x["id"] <=> y["id"]}
|
|
end
|
|
|
|
def accounts_handler
|
|
r = inspect_parameters @options_parser.accounts_params, @provider
|
|
unless r.nil?
|
|
@options_parser.invalid_accounts_command
|
|
abort(r)
|
|
end
|
|
@list = get("/provider/#{@provider}/accounts")
|
|
end
|
|
|
|
end
|