Skip to content

Commit ebfd2a2

Browse files
committed
100% documentation coverage.
1 parent 15558b9 commit ebfd2a2

20 files changed

Lines changed: 198 additions & 5 deletions

lib/teapot.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44
# Copyright, 2012-2026, by Samuel Williams.
55

66
require "teapot/version"
7-
87
require "teapot/context"
9-
10-
module Teapot
11-
end

lib/teapot/command.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
require "console"
2424

2525
module Teapot
26+
# @namespace
2627
module Command
28+
# Represents the top-level command for the teapot CLI.
2729
class Top < Samovar::Command
2830
self.description = "A decentralised package manager and build tool."
2931

@@ -46,18 +48,26 @@ class Top < Samovar::Command
4648
"clean" => Clean,
4749
}, default: "build"
4850

51+
# The project root directory, either from --root option or current working directory.
52+
# @returns [Build::Files::Path] The root directory path.
4953
def root
5054
::Build::Files::Path.expand(@options[:root] || Dir.getwd)
5155
end
5256

57+
# Whether verbose logging is enabled via --verbose flag.
58+
# @returns [Boolean] True if verbose mode is enabled.
5359
def verbose?
5460
@options[:logging] == :verbose
5561
end
5662

63+
# Whether quiet logging is enabled via --quiet flag.
64+
# @returns [Boolean] True if quiet mode is enabled.
5765
def quiet?
5866
@options[:logging] == :quiet
5967
end
6068

69+
# Get the logger for the command.
70+
# @returns [Console::Logger] The configured logger instance.
6171
def logger
6272
@logger ||= Console::Logger.new(Console.logger, verbose: self.verbose?).tap do |logger|
6373
if verbose?
@@ -70,14 +80,20 @@ def logger
7080
end
7181
end
7282

83+
# The build configuration name from -c option or TEAPOT_CONFIGURATION environment variable.
84+
# @returns [String | Nil] The configuration name if specified.
7385
def configuration
7486
@options[:configuration]
7587
end
7688

89+
# Create a context for the project.
90+
# @parameter root [Build::Files::Path] The root directory path.
91+
# @returns [Context] A new context instance.
7792
def context(root = self.root)
7893
Context.new(root, configuration: configuration)
7994
end
8095

96+
# Execute the command.
8197
def call
8298
if @options[:version]
8399
puts "teapot v#{Teapot::VERSION}"

lib/teapot/command/build.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
module Teapot
1111
module Command
12+
# Raised when the build fails.
1213
class BuildFailedError < StandardError
1314
end
1415

16+
# A command to build targets in the project.
1517
class Build < Selection
1618
self.description = "Build the specified target."
1719

@@ -23,6 +25,8 @@ class Build < Selection
2325
many :targets, "Build these targets, or use them to help the dependency resolution process."
2426
split :argv, "Arguments passed to child process(es) of build if any."
2527

28+
# Build the selected targets or default build targets, resolving dependencies and executing the build controller.
29+
# @returns [Build::Dependency::Chain] The dependency chain.
2630
def call
2731
context = parent.context
2832

@@ -65,6 +69,8 @@ def call
6569
return chain
6670
end
6771

72+
# Display task dependencies for debugging, showing which tasks generate which outputs.
73+
# @parameter walker [Build::Walker] The build walker.
6874
def show_dependencies(walker)
6975
outputs = {}
7076

lib/teapot/command/clean.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
module Teapot
99
module Command
10+
# A command to clean build artifacts.
1011
class Clean < Samovar::Command
1112
self.description = "Delete everything in the teapot directory."
1213

14+
# Delete build output directories for the specified targets or all targets.
1315
def call
1416
context = parent.context
1517
logger = parent.logger

lib/teapot/command/clone.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
module Teapot
1515
module Command
16+
# A command to clone a remote repository and fetch all dependencies.
1617
class Clone < Samovar::Command
1718
self.description = "Clone a remote repository and fetch all dependencies."
1819

1920
one :source, "The source repository to clone.", required: true
2021

22+
# Clone packages from their remote repositories using git, parallelizing the operations.
2123
def call
2224
logger = parent.logger
2325

@@ -37,6 +39,11 @@ def call
3739
Fetch[parent: nested].call
3840
end
3941

42+
# Provide credentials for repository authentication.
43+
# @parameter url [String] The repository URL.
44+
# @parameter username [String] The username.
45+
# @parameter types [Array] The credential types allowed.
46+
# @returns [Rugged::Credentials] The credentials object.
4047
def credentials(url, username, types)
4148
# We should prompt for username/password if required...
4249
return Rugged::Credentials::SshKeyFromAgent.new(username: username)

lib/teapot/command/create.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
module Teapot
1313
module Command
14+
# A command to create a new teapot project.
1415
class Create < Samovar::Command
1516
self.description = "Create a new teapot package using the specified repository."
1617

1718
one :name, "The name of the new project in title-case, e.g. 'My Project'.", required: true
1819
one :source, "The source repository to use for fetching packages, e.g. https://github.com/kurocha.", required: true
1920
many :packages, "Any packages you'd like to include in the project.", default: ["generate-project"]
2021

22+
# Create a new project directory structure with default teapot.rb configuration.
2123
def call
2224
logger = parent.logger
2325

@@ -64,6 +66,11 @@ def call
6466
)
6567
end
6668

69+
# Generate the initial project files.
70+
# @parameter root [Build::Files::Path] The project root path.
71+
# @parameter name [String] The project name.
72+
# @parameter source [String] The source repository URL.
73+
# @parameter packages [Array(String)] The packages to include.
6774
def generate_project(root, name, source, packages)
6875
name = ::Build::Name.new(name)
6976

lib/teapot/command/fetch.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
module Teapot
1010
module Command
11+
# Raised when a fetch operation fails.
1112
class FetchError < StandardError
13+
# @parameter package [Package] The package that caused the error.
14+
# @parameter message [String] The error message.
1215
def initialize(package, message)
1316
super(message)
1417
@package = package
@@ -17,6 +20,7 @@ def initialize(package, message)
1720
attr :package
1821
end
1922

23+
# A command to fetch remote packages and dependencies.
2024
class Fetch < Samovar::Command
2125
self.description = "Fetch remote packages according to the specified configuration."
2226

@@ -32,10 +36,13 @@ class Fetch < Samovar::Command
3236

3337
many :packages, "Only update the specified packages, or all packages if none specified."
3438

39+
# Get the context for this command.
40+
# @returns [Context] The current context.
3541
def context
3642
parent.context
3743
end
3844

45+
# Update packages by pulling latest changes from their git remotes, subject to lock file constraints.
3946
def call
4047
selection = context.select
4148

lib/teapot/command/list.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010

1111
module Teapot
1212
module Command
13+
# A command to list project definitions and dependencies.
1314
class List < Selection
1415
self.description = "List provisions and dependencies of the specified package."
1516

17+
# Create a terminal with custom styles for colorizing different definition types in output.
18+
# @parameter output [IO] The output stream.
19+
# @returns [Console::Terminal] The configured terminal.
1620
def terminal(output = $stdout)
1721
Console::Terminal.for(output).tap do |terminal|
1822
terminal[:definition] = terminal.style(nil, nil, :bright)
@@ -24,6 +28,8 @@ def terminal(output = $stdout)
2428
end
2529
end
2630

31+
# Process and display the selection.
32+
# @parameter selection [Select] The selection to process.
2733
def process(selection)
2834
context = selection.context
2935
terminal = self.terminal

lib/teapot/command/selection.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77

88
module Teapot
99
module Command
10+
# Base class for commands that work with selections.
1011
class Selection < Samovar::Command
1112
options
1213

1314
many :targets, "Only consider the specified targets, if any."
1415

16+
# The set of target names to process, or nil if no targets were specified.
17+
# @returns [Set | Nil] The set of target names.
1518
def targets
1619
if @targets and @targets.any?
1720
Set.new(@targets)
1821
end
1922
end
2023

24+
# Get the selection for the given context.
25+
# @parameter context [Context] The project context.
26+
# @returns [Select] The selection.
2127
def selection(context)
2228
if targets = self.targets
2329
context.select(targets)
@@ -26,6 +32,7 @@ def selection(context)
2632
end
2733
end
2834

35+
# Execute the selection command.
2936
def call
3037
context = parent.context
3138

lib/teapot/command/status.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010
module Teapot
1111
module Command
12+
# A command to show git status of packages.
1213
class Status < Selection
1314
self.description = "List the git status of the specified package(s)."
1415

16+
# Create a terminal with custom styles for colorizing git status information.
17+
# @parameter output [IO] The output stream.
18+
# @returns [Console::Terminal] The configured terminal.
1519
def terminal(output = $stdout)
1620
Console::Terminal.for(output).tap do |terminal|
1721
terminal[:worktree_new] = terminal.style(:green)
@@ -20,13 +24,18 @@ def terminal(output = $stdout)
2024
end
2125
end
2226

27+
# Open the git repository for a package, or return nil if the package doesn't have a repository yet.
28+
# @parameter package [Package] The package.
29+
# @returns [Rugged::Repository | Nil] The repository or nil.
2330
def repository_for(package)
2431
Rugged::Repository.new(package.path.to_s)
2532
rescue Rugged::RepositoryError
2633
# In some cases, a repository might not exist yet, so just skip the package.
2734
nil
2835
end
2936

37+
# Process and display the selection.
38+
# @parameter selection [Select] The selection to process.
3039
def process(selection)
3140
context = selection.context
3241
terminal = self.terminal

0 commit comments

Comments
 (0)