class ThreeScaleToolbox::Commands::ApplicationCommand::List::ListSubcommand
Constants
- FIELDS_TO_SHOW
Public Class Methods
command()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 10 def self.command Cri::Command.define do name 'list' usage 'list [opts] <remote>' summary 'list applications' description 'List applications' option nil, :account, 'Filter by account', argument: :required option nil, :service, 'Filter by service', argument: :required option nil, :plan, 'Filter by application plan. Service option required', argument: :required ThreeScaleToolbox::CLI.output_flag(self) param :remote runner ListSubcommand end end
Public Instance Methods
run()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 28 def run validate_option_params applications = if option_account account.applications elsif option_service && option_plan plan.applications elsif option_service service.applications else provider_account_applications end printer.print_collection applications.map(&:attrs) end
Private Instance Methods
account()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 88 def account @account ||= find_account end
find_account()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 92 def find_account Entities::Account.find(remote: remote, ref: option_account).tap do |acc| raise ThreeScaleToolbox::Error, "Account #{option_account} does not exist" if acc.nil? end end
find_plan()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 103 def find_plan Entities::ApplicationPlan.find(service: service, ref: option_plan).tap do |plan| raise ThreeScaleToolbox::Error, "Application plan #{option_plan} does not exist" if plan.nil? end end
find_service()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 81 def find_service Entities::Service.find(remote: remote, ref: option_service).tap do |svc| raise ThreeScaleToolbox::Error, "Service #{option_service} does not exist" if svc.nil? end end
option_account()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 69 def option_account options[:account] end
option_plan()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 73 def option_plan options[:plan] end
option_service()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 65 def option_service options[:service] end
plan()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 99 def plan @plan ||= find_plan end
printer()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 113 def printer # keep backwards compatibility options.fetch(:output, CLI::CustomTablePrinter.new(FIELDS_TO_SHOW)) end
provider_account_applications()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 54 def provider_account_applications app_attrs_list = remote.list_applications if app_attrs_list.respond_to?(:has_key?) && (errors = app_attrs_list['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Provider account applications not read', errors) end app_attrs_list.map do |app_attrs| Entities::Application.new(id: app_attrs.fetch('id'), remote: remote, attrs: app_attrs) end end
remote()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 109 def remote @remote ||= threescale_client(arguments[:remote]) end
service()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 77 def service @service ||= find_service end
validate_option_params()
click to toggle source
# File lib/3scale_toolbox/commands/application_command/list_command.rb, line 46 def validate_option_params raise ThreeScaleToolbox::Error, '--account and --service are mutually exclusive' \ if option_service && option_account raise ThreeScaleToolbox::Error, '--plan requires --service option' \ if option_plan && option_service.nil? end