amonks / run

Go run some tasks!
https://amonks.github.io/run/
Other
19 stars 4 forks source link

think deeply about package layout #96

Open amonks opened 5 months ago

amonks commented 5 months ago

I don't want to change this ever after 1.0, so I'd like to make sure it's right before releasing that version.

Some considerations:

amonks commented 5 months ago

this feels pretty good to me:

// package tasks

type Task interface {
    Metadata() TaskMetadata
    Start(context.Context, io.Writer) (<-chan struct{}, error) // chan is `ready`
}

type TaskMetadata struct{}

type Tasks struct{}

func (Tasks) Validate() error
func (Tasks) IDs() []string
func (Tasks) Task(id string) Task
func (Tasks) Watches() []string

func (Tasks) Subtree(id string) Tasks

// list of ids where metadata matches the argument
func (Tasks) WithWatch(watch string) []string
func (Tasks) WithDependency(dependency string) []string
func (Tasks) WithTrigger(trigger string) []string
// package script

type Script struct{}

func New(cwd, script string) Script
func (Script) Start(context.Context, io.Writer) error

type ScriptTask struct {
    script   Script
    metadata TaskMetadata
}

var _ Task = ScriptTask{}

func NewScriptTask(Script, TaskMetadata)
func (ScriptTask) CWD() string // so that Tasks.Validate() can check for ../ watches
func (ScriptTask) Metadata() TaskMetadata
func (ScriptTask) Start(context.Context, io.Writer) (<-chan struct{}, error)
// package taskfile

type Taskfile struct{}

func Load(string) (Taskfile, error)
func (Taskfile) Validate() error
func (Taskfile) Tasks() Tasks
// package runner

type Runner struct{}

func New(tasks []Task) Runner
func (Runner) Start(context.Context, MultiWriter, entryPointTaskIDs ...string) error
func (Runner) Add(id string) error     // add more entry-point tasks mid-run
func (Runner) Remove(id string) error  // remove entry-point tasks mid-run
func (Runner) Invalidate(id string) error

func (Runner) Status() map[string]TaskStatus

type MultiWriter interface {
    Writer(id string) io.Writer
}

type TaskStatus int
// package tui

func Start(ctx context.Context, tasks Tasks, entryPointTaskIDs ...string) error
// package printer

type Printer struct{}

var _ MultiWriter = Printer{}

func NewPrinter(gutterWidth int) Printer
func (Printer) Writer(string) io.Writer