Documentation
¶
Overview ¶
Package workflow provides a structured engine for executing sequential, multi-step CLI operations. It separates the "what" (Steps) from the "how" (Runner), allowing for reusable logic, consistent error handling, and standardized user interaction.
Core Concepts ¶
- Step: An interface defining a single unit of work. It has a Description, a PreCheck (validation), and an Execute (action) phase.
- Runner: The engine that orchestrates the execution of Steps. It handles UI presentation, confirmation prompts, and error propagation.
- PresenterInterface: An abstraction for UI output, allowing the workflow to be tested without writing to actual stdout/stderr.
Usage Pattern ¶
runner := workflow.NewRunner(presenter, assumeYes)
err := runner.Run(ctx, "My Workflow Title",
&MyStep1{},
&MyStep2{},
)
PreChecks vs Execution ¶
The Runner executes all PreChecks first. If any PreCheck fails, the workflow aborts immediately. This ensures the environment is safe before any state changes occur. If all PreChecks pass, the Runner (optionally) prompts the user for confirmation before proceeding to the Execute phase of each step.
Index ¶
- func GetValidatedBranchName(ctx context.Context, branchNameFlag string, cfg *config.Config, ...) (string, error)
- type CheckAndPromptStashStep
- type CheckGoEnvStep
- type CheckOnMainBranchStep
- type ConfigurePathStep
- type CreateAndPushBranchStep
- type EnsureNotMainBranchStep
- type EnsureStagedStep
- type GenerateCommitPromptStep
- type InstallGoToolsStep
- type PresenterInterface
- type Runner
- type Step
- type UpdateMainBranchStep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetValidatedBranchName ¶
func GetValidatedBranchName( ctx context.Context, branchNameFlag string, cfg *config.Config, presenter PresenterInterface, gitClient *git.GitClient, assumeYes bool, ) (string, error)
GetValidatedBranchName is a helper function that can be used by the command before initializing the workflow. It's not a step itself.
Types ¶
type CheckAndPromptStashStep ¶
type CheckAndPromptStashStep struct {
GitClient *git.GitClient
Presenter PresenterInterface
AssumeYes bool
DidStash bool // ADDED: This field will track if a stash was performed.
}
CheckAndPromptStashStep checks for a clean workspace and offers to stash changes.
func (*CheckAndPromptStashStep) Description ¶
func (s *CheckAndPromptStashStep) Description() string
Description returns a description of the step.
type CheckGoEnvStep ¶ added in v0.6.0
type CheckGoEnvStep struct {
ExecClient *exec.ExecutorClient
Presenter PresenterInterface
}
CheckGoEnvStep verifies Go is installed and logs the version.
func (*CheckGoEnvStep) Description ¶ added in v0.6.0
func (s *CheckGoEnvStep) Description() string
Description returns the step description.
type CheckOnMainBranchStep ¶
type CheckOnMainBranchStep struct {
GitClient *git.GitClient
Presenter PresenterInterface
}
CheckOnMainBranchStep verifies that the current branch is the main branch.
func (*CheckOnMainBranchStep) Description ¶
func (s *CheckOnMainBranchStep) Description() string
Description returns a description of the step.
type ConfigurePathStep ¶ added in v0.6.0
type ConfigurePathStep struct {
Presenter PresenterInterface
AssumeYes bool
}
ConfigurePathStep ensures $HOME/go/bin is in .bashrc.
func (*ConfigurePathStep) Description ¶ added in v0.6.0
func (s *ConfigurePathStep) Description() string
Description returns the step description.
type CreateAndPushBranchStep ¶
CreateAndPushBranchStep creates and pushes a new branch.
func (*CreateAndPushBranchStep) Description ¶
func (s *CreateAndPushBranchStep) Description() string
Description returns a description of the step.
type EnsureNotMainBranchStep ¶ added in v0.4.1
type EnsureNotMainBranchStep struct {
GitClient *git.GitClient
Presenter PresenterInterface
}
EnsureNotMainBranchStep ensures the user is NOT on the main branch.
func (*EnsureNotMainBranchStep) Description ¶ added in v0.4.1
func (s *EnsureNotMainBranchStep) Description() string
Description returns a description of the step.
type EnsureStagedStep ¶ added in v0.4.1
type EnsureStagedStep struct {
GitClient *git.GitClient
Presenter PresenterInterface
AssumeYes bool
}
EnsureStagedStep ensures there are staged changes, prompting to add if necessary.
func (*EnsureStagedStep) Description ¶ added in v0.4.1
func (s *EnsureStagedStep) Description() string
Description returns a description of the step.
type GenerateCommitPromptStep ¶ added in v0.4.1
type GenerateCommitPromptStep struct {
GitClient *git.GitClient
Presenter PresenterInterface
}
GenerateCommitPromptStep reads the state and outputs the AI prompt.
func (*GenerateCommitPromptStep) Description ¶ added in v0.4.1
func (s *GenerateCommitPromptStep) Description() string
Description returns a description of the step.
type InstallGoToolsStep ¶ added in v0.6.0
type InstallGoToolsStep struct {
ExecClient *exec.ExecutorClient
Presenter PresenterInterface
}
InstallGoToolsStep force-installs the required tools.
func (*InstallGoToolsStep) Description ¶ added in v0.6.0
func (s *InstallGoToolsStep) Description() string
Description returns the step description.
type PresenterInterface ¶
type PresenterInterface interface {
Error(format string, a ...any)
Warning(format string, a ...any)
Info(format string, a ...any)
Success(format string, a ...any)
Detail(format string, a ...any)
Step(format string, a ...any)
Header(format string, a ...any)
Summary(format string, a ...any)
Newline()
PromptForConfirmation(prompt string) (bool, error)
PromptForInput(prompt string) (string, error)
Advice(format string, a ...any)
}
PresenterInterface defines the UI methods the workflow engine needs. This decouples the engine from the concrete ui.Presenter.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner manages the execution of a series of workflow steps.
func NewRunner ¶
func NewRunner(presenter PresenterInterface, assumeYes bool) *Runner
NewRunner creates a new workflow runner.
type Step ¶
type Step interface {
// Description returns a user-friendly string explaining what this step will do.
// This is used to build the "plan" shown to the user before confirmation.
Description() string
// PreCheck runs any prerequisite validations before the main execution.
// If it returns an error, the entire workflow is aborted.
PreCheck(ctx context.Context) error
// Execute performs the primary action of the step.
Execute(ctx context.Context) error
}
Step represents a single, discrete, and reusable action within a larger workflow.
type UpdateMainBranchStep ¶
UpdateMainBranchStep updates the main branch from the remote.
func (*UpdateMainBranchStep) Description ¶
func (s *UpdateMainBranchStep) Description() string
Description returns a description of the step.