TeapotSourceTeapotCommandTop

class Top

Represents the top-level command for the teapot CLI.

Nested

Definitions

def root

The project root directory, either from --root option or current working directory.

Signature

returns Build::Files::Path

The root directory path.

Implementation

def root
	::Build::Files::Path.expand(@options[:root] || Dir.getwd)
end

def verbose?

Whether verbose logging is enabled via --verbose flag.

Signature

returns Boolean

True if verbose mode is enabled.

Implementation

def verbose?
	@options[:logging] == :verbose
end

def quiet?

Whether quiet logging is enabled via --quiet flag.

Signature

returns Boolean

True if quiet mode is enabled.

Implementation

def quiet?
	@options[:logging] == :quiet
end

def logger

Get the logger for the command.

Signature

returns Console::Logger

The configured logger instance.

Implementation

def logger
	@logger ||= Console::Logger.new(Console.logger, verbose: self.verbose?).tap do |logger|
		if verbose?
			logger.debug!
		elsif quiet?
			logger.warn!
		else
			logger.info!
		end
	end
end

def configuration

The build configuration name from -c option or TEAPOT_CONFIGURATION environment variable.

Signature

returns String | Nil

The configuration name if specified.

Implementation

def configuration
	@options[:configuration]
end

def context(root = self.root)

Create a context for the project.

Signature

parameter root Build::Files::Path

The root directory path.

returns Context

A new context instance.

Implementation

def context(root = self.root)
	Context.new(root, configuration: configuration)
end

def call

Execute the command.

Implementation

def call
	if @options[:version]
		puts "teapot v#{Teapot::VERSION}"
	elsif @options[:help]
		print_usage(output: $stdout)
	else
		@command.call
	end
rescue Teapot::IncompatibleTeapotError => error
	logger.error(command, error) do
		"Supported minimum version #{Teapot::MINIMUM_LOADER_VERSION.dump} to #{Teapot::LOADER_VERSION.dump}."
	end
	
	raise
rescue ::Build::Dependency::UnresolvedDependencyError => error
	logger.error(command, error) do |buffer|
		buffer.puts "Unresolved dependencies:"
		
		error.chain.unresolved.each do |name, parent|
			buffer.puts "#{parent} depends on #{name.inspect}"
			
			conflicts = error.chain.conflicts[name]
			
			if conflicts
				conflicts.each do |conflict|
					buffer.puts " - provided by #{conflict.name}"
				end
			end
		end
		
		buffer.puts "Cannot continue due to unresolved dependencies!"
	end
	
	raise
rescue StandardError => error
	logger.error(command, error)
	
	raise
end