Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions packages/go/driver/internal/app/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package app
import (
"context"
"fmt"
"io"
"strings"

"go.ollin.sh/fmtkit/driver/internal/console"
"go.ollin.sh/fmtkit/driver/internal/gitfiles"
"go.ollin.sh/fmtkit/driver/internal/gotool"
"go.ollin.sh/fmtkit/driver/internal/orchestrator"
"go.ollin.sh/fmtkit/driver/internal/tsruntime"
report "go.ollin.sh/fmtkit/driver/report"
"go.ollin.sh/fmtkit/driver/internal/pipeline"
)

// runFormat formats what diverges from HEAD — modified files, staged or not,
Expand Down Expand Up @@ -48,37 +46,32 @@ func (d *deps) runFormatAll(ctx context.Context, args []string) int {
return d.runPipeline(ctx, []string{"."}, opts, gitfiles.SelectionAll)
}

// runPipeline frames the format run (target header, completion footer) around
// the typed steps it builds for the selection, handing them to the generic
// pipeline. Color is resolved once here, at the composition root.
func (d *deps) runPipeline(ctx context.Context, paths []string, opts formatOptions, selection gitfiles.Selection) int {
pipeline := orchestrator.Pipeline{
Tools: orchestrator.Tools{
TS: func(ctx context.Context, scopes []string, output io.Writer) error {
assets, err := tsruntime.Resolve(d.version)

if err != nil {
return err
}

return tsruntime.NewInvoker(assets).RunPipeline(ctx, tsruntime.Request{Scopes: scopes, Selection: selection, Stdout: output, Stderr: output})
},
Lint: func(ctx context.Context, scopes []string, output io.Writer) error {
assets, err := tsruntime.Resolve(d.version)

if err != nil {
return err
}

return tsruntime.NewInvoker(assets).RunLint(ctx, tsruntime.Request{Scopes: scopes, Selection: selection, Fix: true, Stdout: output, Stderr: output})
},
Go: func(ctx context.Context, args []string, output io.Writer) int {
return gotool.
Runner{Stdout: output, Stderr: output, Scope: selection}.
Run(ctx, report.ModeFormat, args[1:])
},
},
Steps: opts.steps,
Quiet: opts.quiet,
Stderr: d.stderr,
if len(paths) == 0 {
paths = []string{"."}
}

return pipeline.RunFormat(ctx, paths)
printer := console.NewPrinter(d.stderr, console.DetectColor(d.stderr))

printer.Section("Formatting target(s)")
printer.Detail("paths", strings.Join(paths, " "))

pipe := pipeline.Pipeline{
Steps: d.formatSteps(paths, opts.steps, selection),
Quiet: opts.quiet,
Printer: printer,
Stderr: d.stderr,
}

if code := pipe.Run(ctx); code != 0 {
return code
}

printer.Section("Formatting complete")
printer.SuccessDetail("status", "done")

return 0
}
4 changes: 1 addition & 3 deletions packages/go/driver/internal/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package app
import (
"fmt"
"strings"

"go.ollin.sh/fmtkit/driver/internal/orchestrator"
)

type formatOptions struct {
steps orchestrator.Steps
steps stepSelection
quiet bool
}

Expand Down
Loading
Loading