Class: Teapot::Command::Top
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Teapot::Command::Top
- Defined in:
- lib/teapot/command.rb
Overview
Represents the top-level command for the teapot CLI.
Instance Method Summary collapse
-
#call ⇒ Object
Execute the command.
-
#configuration ⇒ Object
The build configuration name from -c option or TEAPOT_CONFIGURATION environment variable.
-
#context(root = self.root) ⇒ Object
Create a context for the project.
-
#logger ⇒ Object
Get the logger for the command.
-
#quiet? ⇒ Boolean
Whether quiet logging is enabled via –quiet flag.
-
#root ⇒ Object
The project root directory, either from –root option or current working directory.
-
#verbose? ⇒ Boolean
Whether verbose logging is enabled via –verbose flag.
Instance Method Details
#call ⇒ Object
Execute the command.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/teapot/command.rb', line 97 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 |
#configuration ⇒ Object
The build configuration name from -c option or TEAPOT_CONFIGURATION environment variable.
85 86 87 |
# File 'lib/teapot/command.rb', line 85 def configuration @options[:configuration] end |
#context(root = self.root) ⇒ Object
Create a context for the project.
92 93 94 |
# File 'lib/teapot/command.rb', line 92 def context(root = self.root) Context.new(root, configuration: configuration) end |
#logger ⇒ Object
Get the logger for the command.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/teapot/command.rb', line 71 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 |
#quiet? ⇒ Boolean
Whether quiet logging is enabled via –quiet flag.
65 66 67 |
# File 'lib/teapot/command.rb', line 65 def quiet? @options[:logging] == :quiet end |
#root ⇒ Object
The project root directory, either from –root option or current working directory.
53 54 55 |
# File 'lib/teapot/command.rb', line 53 def root ::Build::Files::Path.(@options[:root] || Dir.getwd) end |
#verbose? ⇒ Boolean
Whether verbose logging is enabled via –verbose flag.
59 60 61 |
# File 'lib/teapot/command.rb', line 59 def verbose? @options[:logging] == :verbose end |