Skip to content

Commit 5afed0a

Browse files
authored
Reduce duplication in text-only UI and TUI (#565)
This introduces the concept of a `batchExecUI`: the UI that displays the status of a batch spec execution. Both `batchExecTUI` and `batchExecJSONLinesUI` implement that interface and can thus be used interchangeably. The result is that we can get rid of the duplicated code paths. Note: this is not as nice as it could be, because I want to be careful and only change what is necessary in this PR to get rid of the duplication (vs. rethinking how we batch spec execution reports progress, etc.) So please review from that point of view.
1 parent 337de5f commit 5afed0a

File tree

9 files changed

+742
-558
lines changed

9 files changed

+742
-558
lines changed

cmd/src/batch_apply.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,24 @@ Examples:
4141
ctx, cancel := contextCancelOnInterrupt(context.Background())
4242
defer cancel()
4343

44-
var err error
44+
var ui batchExecUI
4545
if flags.textOnly {
46-
err = textOnlyExecuteBatchSpec(ctx, executeBatchSpecOpts{
47-
flags: flags,
48-
client: cfg.apiClient(flags.api, flagSet.Output()),
49-
50-
applyBatchSpec: true,
51-
})
52-
if err != nil {
53-
fmt.Printf("ERROR: %s\n", err)
54-
return &exitCodeError{nil, 1}
55-
}
46+
ui = &batchExecJSONLinesUI{}
5647
} else {
5748
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
58-
err = executeBatchSpec(ctx, executeBatchSpecOpts{
59-
flags: flags,
60-
out: out,
61-
client: cfg.apiClient(flags.api, flagSet.Output()),
62-
63-
applyBatchSpec: true,
64-
})
65-
if err != nil {
66-
printExecutionError(out, err)
67-
out.Write("")
68-
return &exitCodeError{nil, 1}
69-
}
49+
ui = &batchExecTUI{out: out}
50+
}
51+
52+
err := executeBatchSpec(ctx, executeBatchSpecOpts{
53+
flags: flags,
54+
client: cfg.apiClient(flags.api, flagSet.Output()),
55+
56+
applyBatchSpec: true,
57+
58+
ui: ui,
59+
})
60+
if err != nil {
61+
return &exitCodeError{nil, 1}
7062
}
7163

7264
return nil

0 commit comments

Comments
 (0)