module Kontena::Cli::Stacks::Common
Public Instance Methods
abort_on_validation_errors(errors, filename = nil)
click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 196 def abort_on_validation_errors(errors, filename = nil) return if errors.nil? || errors.empty? $stderr.puts pastel.red("#{"(#{filename}) " if filename} YAML validation failed! Aborting.") display_notifications(errors, :red) abort end
current_dir()
click to toggle source
@return [String]
# File lib/kontena/cli/stacks/common.rb, line 182 def current_dir File.basename(Dir.getwd) end
display_notifications(messages, color = :yellow)
click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 186 def display_notifications(messages, color = :yellow) $stderr.puts(pastel.send(color, messages.to_yaml.gsub(/^---$/, ''))) end
hint_on_validation_notifications(notifications, filename = nil)
click to toggle source
# File lib/kontena/cli/stacks/common.rb, line 190 def hint_on_validation_notifications(notifications, filename = nil) return if notifications.nil? || notifications.empty? $stderr.puts pastel.yellow("#{"(#{filename}) " if filename}YAML contains the following unsupported options and they were rejected:") display_notifications(notifications) end
loader()
click to toggle source
@return [StackFileLoader] a loader for the stack origin defined through command-line options
# File lib/kontena/cli/stacks/common.rb, line 13 def loader @loader ||= loader_class.for(source) end
loader_class()
click to toggle source
@return [Class] an accessor to StackFileLoader constant, for testing purposes
# File lib/kontena/cli/stacks/common.rb, line 41 def loader_class ::Kontena::Cli::Stacks::YAML::StackFileLoader end
reader()
click to toggle source
@return [YAML::Reader] a YAML
reader for the target file
# File lib/kontena/cli/stacks/common.rb, line 18 def reader @reader ||= loader.reader end
set_env_variables(stack, grid, platform = grid)
click to toggle source
Sets environment variables from parameters @param stack [String] current stack name @param grid [String] current grid name @param platform [String] current platform name, defaults to param grid value
# File lib/kontena/cli/stacks/common.rb, line 175 def set_env_variables(stack, grid, platform = grid) ENV['STACK'] = stack ENV['GRID'] = grid ENV['PLATFORM'] = platform end
stack()
click to toggle source
An accessor to the YAML
Reader outcome. Passes parent name, values from command line and the stackname to the reader.
@return [Hash]
# File lib/kontena/cli/stacks/common.rb, line 32 def stack @stack ||= reader.execute( name: stack_name, parent_name: self.respond_to?(:parent_name) ? self.parent_name : nil, values: (self.respond_to?(:values_from_options) ? self.values_from_options : {}) ) end
stack_name()
click to toggle source
Stack name read from -n parameter or the stack file @return [String]
# File lib/kontena/cli/stacks/common.rb, line 24 def stack_name @stack_name ||= (self.respond_to?(:name) && self.name) ? self.name : loader.stack_name.stack end
stacks_client()
click to toggle source
An accessor to stack registry client @return [Kontena::StacksClient]
# File lib/kontena/cli/stacks/common.rb, line 205 def stacks_client @stacks_client ||= Kontena::StacksClient.new(current_account.stacks_url, current_account.token, read_requires_token: current_account.stacks_read_authentication) end