Documentation
¶
Index ¶
- Variables
- func DeleteTask(name string) error
- func DeleteWorkspace(name string) error
- func FindTaskByName(name string) (*models.Task, error)
- func FindWorkspaceByName(name string) (*models.Workspace, error)
- func ImportTasks(tasks []models.Task) error
- func ImportWorkspaces(workspaces []models.Workspace) error
- func OpenSource(source string) (io.ReadCloser, error)
- func ReadJSONSource[T any](source string) (T, error)
- func ReadTasks() ([]models.Task, error)
- func ReadWorkspaces() ([]models.Workspace, error)
- func SaveTask(task models.Task) error
- func SaveWorkspace(workspace models.Workspace) error
- func UpdateTask(originalName string, updatedTask models.Task) error
- func UpdateWorkspace(originalName string, updatedWorkspace models.Workspace) error
- func ValidateTaskBatch(tasks []models.Task) error
- func ValidateWorkspaceBatch(workspaces []models.Workspace) error
- type JSONRepository
- func (r *JSONRepository[T]) Delete(name string) error
- func (r *JSONRepository[T]) FindByName(name string) (*T, error)
- func (r *JSONRepository[T]) ReadAll() ([]T, error)
- func (r *JSONRepository[T]) Save(item T) error
- func (r *JSONRepository[T]) Update(originalName string, updated T) error
- func (r *JSONRepository[T]) WriteAll(items []T) error
- type NamedEntity
Constants ¶
This section is empty.
Variables ¶
var ( // TasksSaveFile holds the absolute path to the tasks.json file in the user's config directory. TasksSaveFile string )
var ( // WorkspacesSaveFile holds the absolute path to the workspaces.json file in the user's config directory. WorkspacesSaveFile string )
Functions ¶
func DeleteTask ¶
DeleteTask removes a task from the local configuration file by name.
func DeleteWorkspace ¶
DeleteWorkspace removes a workspace from the local configuration file by name.
func FindTaskByName ¶
FindTaskByName retrieves a task by its name from the saved tasks.
func FindWorkspaceByName ¶
FindWorkspaceByName retrieves a workspace by its name from the saved workspaces.
func ImportTasks ¶
ImportTasks validates the whole batch (VAL-001, VAL-003, VAL-004, VAL-005) and writes all entries only if every entry is valid. On failure it returns an aggregate error and writes nothing.
func ImportWorkspaces ¶
ImportWorkspaces mirrors ImportTasks for workspaces (VAL-002, VAL-004, VAL-005).
func OpenSource ¶
func OpenSource(source string) (io.ReadCloser, error)
OpenSource returns a reader for the given --from-json value: os.Stdin when source == "-", otherwise the opened file. The returned ReadCloser is always safe to Close.
func ReadJSONSource ¶
ReadJSONSource opens source via OpenSource, reads all bytes, and unmarshals them into T. It consolidates the open-read-unmarshal sequence shared by all --from-json command handlers.
func ReadWorkspaces ¶
ReadWorkspaces loads all workspaces from the persistence file.
func SaveWorkspace ¶
SaveWorkspace saves a workspace to the local configuration file.
func UpdateTask ¶
UpdateTask modifies an existing task in the local configuration file.
func UpdateWorkspace ¶
UpdateWorkspace replaces the workspace stored under originalName with updatedWorkspace. The replacement is a single atomic write, so a rename never leaves the file with a duplicate or a missing record.
func ValidateTaskBatch ¶
ValidateTaskBatch checks the batch for all problems (VAL-001, VAL-003, VAL-004, VAL-005) without modifying any file. Returns nil when all entries are valid.
func ValidateWorkspaceBatch ¶
ValidateWorkspaceBatch checks the batch (VAL-002, VAL-004, VAL-005) without modifying any file.
Types ¶
type JSONRepository ¶
type JSONRepository[T NamedEntity] struct { // contains filtered or unexported fields }
JSONRepository persists a slice of T as a single JSON object file whose only top-level key is jsonKey, e.g. {"tasks": [...]}. The append rule is injected via onAppend (Strategy) so each repository can choose its own policy; both current repositories use the shared rejectDuplicateName strategy.
The save-file path is resolved lazily through getSaveFile rather than captured at construction time, so callers (notably tests) that reassign the package path variable after init() are honored on the next operation.
func NewTaskRepository ¶
func NewTaskRepository(getSaveFile func() string) *JSONRepository[models.Task]
NewTaskRepository builds the task repository: tasks are keyed under "tasks" and rejected on a case-sensitive name collision, since the task name is the handle every read path (find, run, completion, workspace selector) keys on.
func NewWorkspaceRepository ¶
func NewWorkspaceRepository(getSaveFile func() string) *JSONRepository[models.Workspace]
NewWorkspaceRepository builds the workspace repository: workspaces are keyed under "workspaces" and rejected on a case-sensitive name collision.
func (*JSONRepository[T]) Delete ¶
func (r *JSONRepository[T]) Delete(name string) error
Delete removes the item whose name equals name, matching case-sensitively. Deleting a non-existent name succeeds silently, preserving prior behavior.
func (*JSONRepository[T]) FindByName ¶
func (r *JSONRepository[T]) FindByName(name string) (*T, error)
FindByName retrieves the item whose name matches name. The comparison is case-sensitive, matching the uniqueness rule enforced by onAppend on write, so a lookup never resolves a name the repository would treat as distinct.
func (*JSONRepository[T]) ReadAll ¶
func (r *JSONRepository[T]) ReadAll() ([]T, error)
ReadAll loads every persisted item, creating the backing file on first use. An empty file yields (nil, nil); malformed JSON returns the unmarshal error.
func (*JSONRepository[T]) Save ¶
func (r *JSONRepository[T]) Save(item T) error
Save appends item according to the injected onAppend strategy and persists the result. The strategy decides whether a duplicate name is allowed.
func (*JSONRepository[T]) Update ¶
func (r *JSONRepository[T]) Update(originalName string, updated T) error
Update replaces the item stored under originalName with updated, matching the original name case-sensitively. It returns an error when no such item exists.
func (*JSONRepository[T]) WriteAll ¶
func (r *JSONRepository[T]) WriteAll(items []T) error
WriteAll atomically replaces the whole file with items, serialized as {jsonKey: items}. It writes to a temporary file in the same directory and renames it over the destination: os.Rename is atomic within a filesystem, so a crash mid-write can never leave a truncated or corrupt JSON file behind.
type NamedEntity ¶
type NamedEntity interface {
GetName() string
}
NamedEntity is the constraint for items persisted by JSONRepository: any type that exposes its unique name. It is defined here, where it is consumed, per the project's Go interface guideline.