Documentation
¶
Overview ¶
Package timer provides timing functionality for tracking command execution duration.
The timer package implements a simple, stateful timer that tracks total elapsed time and per-stage elapsed time for CLI command operations. It integrates with the notify package to display timing information in command output.
Example usage for single-stage command:
timer := timer.New()
timer.Start()
// ... perform operation ...
total, stage := timer.GetTiming()
fmt.Printf("Operation completed [%s]\n", total)
Example usage for multi-stage command:
timer := timer.New()
timer.Start()
// ... stage 1 ...
timer.NewStage()
// ... stage 2 ...
total, stage := timer.GetTiming()
fmt.Printf("Operation completed [%s total|%s stage]\n", total, stage)
Index ¶
- type Impl
- type MockTimer
- type MockTimer_Expecter
- type MockTimer_GetTiming_Call
- func (_c *MockTimer_GetTiming_Call) Return(total time.Duration, stage time.Duration) *MockTimer_GetTiming_Call
- func (_c *MockTimer_GetTiming_Call) Run(run func()) *MockTimer_GetTiming_Call
- func (_c *MockTimer_GetTiming_Call) RunAndReturn(run func() (time.Duration, time.Duration)) *MockTimer_GetTiming_Call
- type MockTimer_NewStage_Call
- type MockTimer_Start_Call
- type MockTimer_Stop_Call
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Impl ¶
type Impl struct {
// contains filtered or unexported fields
}
Impl is the concrete implementation of the Timer interface.
func New ¶
func New() *Impl
New creates a new Timer instance. The timer must be started with Start() before use.
func (*Impl) GetTiming ¶
GetTiming returns the current elapsed durations. Returns (total, stage) where:
- total: time elapsed since Start() was called
- stage: time elapsed since last NewStage() or Start()
If Start() has not been called, returns (0, 0). Can be called multiple times without side effects.
func (*Impl) NewStage ¶
func (t *Impl) NewStage()
NewStage marks a transition to a new stage. Resets the stage timer while preserving total elapsed time.
type MockTimer ¶ added in v1.14.0
MockTimer is an autogenerated mock type for the Timer type
func NewMockTimer ¶ added in v1.14.0
NewMockTimer creates a new instance of MockTimer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockTimer) EXPECT ¶ added in v1.14.0
func (_m *MockTimer) EXPECT() *MockTimer_Expecter
func (*MockTimer) GetTiming ¶ added in v1.14.0
GetTiming provides a mock function for the type MockTimer
func (*MockTimer) NewStage ¶ added in v1.14.0
func (_mock *MockTimer) NewStage()
NewStage provides a mock function for the type MockTimer
type MockTimer_Expecter ¶ added in v1.14.0
type MockTimer_Expecter struct {
// contains filtered or unexported fields
}
func (*MockTimer_Expecter) GetTiming ¶ added in v1.14.0
func (_e *MockTimer_Expecter) GetTiming() *MockTimer_GetTiming_Call
GetTiming is a helper method to define mock.On call
func (*MockTimer_Expecter) NewStage ¶ added in v1.14.0
func (_e *MockTimer_Expecter) NewStage() *MockTimer_NewStage_Call
NewStage is a helper method to define mock.On call
func (*MockTimer_Expecter) Start ¶ added in v1.14.0
func (_e *MockTimer_Expecter) Start() *MockTimer_Start_Call
Start is a helper method to define mock.On call
func (*MockTimer_Expecter) Stop ¶ added in v1.14.0
func (_e *MockTimer_Expecter) Stop() *MockTimer_Stop_Call
Stop is a helper method to define mock.On call
type MockTimer_GetTiming_Call ¶ added in v1.14.0
MockTimer_GetTiming_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTiming'
func (*MockTimer_GetTiming_Call) Return ¶ added in v1.14.0
func (_c *MockTimer_GetTiming_Call) Return(total time.Duration, stage time.Duration) *MockTimer_GetTiming_Call
func (*MockTimer_GetTiming_Call) Run ¶ added in v1.14.0
func (_c *MockTimer_GetTiming_Call) Run(run func()) *MockTimer_GetTiming_Call
func (*MockTimer_GetTiming_Call) RunAndReturn ¶ added in v1.14.0
func (_c *MockTimer_GetTiming_Call) RunAndReturn(run func() (time.Duration, time.Duration)) *MockTimer_GetTiming_Call
type MockTimer_NewStage_Call ¶ added in v1.14.0
MockTimer_NewStage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewStage'
func (*MockTimer_NewStage_Call) Return ¶ added in v1.14.0
func (_c *MockTimer_NewStage_Call) Return() *MockTimer_NewStage_Call
func (*MockTimer_NewStage_Call) Run ¶ added in v1.14.0
func (_c *MockTimer_NewStage_Call) Run(run func()) *MockTimer_NewStage_Call
func (*MockTimer_NewStage_Call) RunAndReturn ¶ added in v1.14.0
func (_c *MockTimer_NewStage_Call) RunAndReturn(run func()) *MockTimer_NewStage_Call
type MockTimer_Start_Call ¶ added in v1.14.0
MockTimer_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
func (*MockTimer_Start_Call) Return ¶ added in v1.14.0
func (_c *MockTimer_Start_Call) Return() *MockTimer_Start_Call
func (*MockTimer_Start_Call) Run ¶ added in v1.14.0
func (_c *MockTimer_Start_Call) Run(run func()) *MockTimer_Start_Call
func (*MockTimer_Start_Call) RunAndReturn ¶ added in v1.14.0
func (_c *MockTimer_Start_Call) RunAndReturn(run func()) *MockTimer_Start_Call
type MockTimer_Stop_Call ¶ added in v1.14.0
MockTimer_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop'
func (*MockTimer_Stop_Call) Return ¶ added in v1.14.0
func (_c *MockTimer_Stop_Call) Return() *MockTimer_Stop_Call
func (*MockTimer_Stop_Call) Run ¶ added in v1.14.0
func (_c *MockTimer_Stop_Call) Run(run func()) *MockTimer_Stop_Call
func (*MockTimer_Stop_Call) RunAndReturn ¶ added in v1.14.0
func (_c *MockTimer_Stop_Call) RunAndReturn(run func()) *MockTimer_Stop_Call
type Timer ¶
type Timer interface {
// Start initializes timing tracking. Sets both total and stage
// start times to the current time. Can be called multiple times
// to reset the timer.
Start()
// NewStage marks a stage transition.
// Resets the stage timer while preserving total elapsed time.
NewStage()
// GetTiming returns the current elapsed durations.
// Returns (total, stage) where:
// - total: time elapsed since Start()
// - stage: time elapsed since last NewStage() or Start()
// Can be called multiple times without side effects.
GetTiming() (total, stage time.Duration)
// Stop signals completion of timing. This is optional and
// provided for future extensibility. Currently a no-op.
Stop()
}
Timer tracks elapsed time for CLI command execution.
Timer provides methods to start timing, mark stage transitions, and retrieve current timing information. It is designed for single-threaded CLI command execution.