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
8 changes: 8 additions & 0 deletions cmd/dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func plannedStatus(dryRun bool, realStatus string) string {
return realStatus
}

// renderOperation renders a command's operation output through the shared
// command output writer: the text closure produces the human-readable form and
// the JSON form is the standard operation envelope. Dry-run branches use this
// to avoid duplicating the commandOutput/newJSONCommandOperationOutput glue.
func renderOperation(cmd *cobra.Command, input any, results []jsonOperationResult, warnings []jsonWarning, text func(io.Writer) error) error {
return commandOutput(cmd).Render(text, newJSONCommandOperationOutput(cmd, input, results, warnings))
}

func writeDryRunLine(w io.Writer, verb, path string) error {
_, err := fmt.Fprintf(w, "Would %s %s\n", verb, path)
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func mkdir(cmd *cobra.Command, args []string) (err error) {

if opts.dryRun {
result := newPlannedMkdirResult(dst, opts)
return commandOutput(cmd).Render(func(w io.Writer) error {
return renderOperation(cmd, result.Input, []jsonOperationResult{mkdirOperationResult(result)}, nil, func(w io.Writer) error {
return writeDryRunLine(w, "create directory", result.displayPath())
}, newJSONCommandOperationOutput(cmd, result.Input, []jsonOperationResult{mkdirOperationResult(result)}, nil))
})
}

arg := files.NewCreateFolderArg(dst)
Expand Down
4 changes: 2 additions & 2 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func restore(cmd *cobra.Command, args []string) (err error) {
}
if opts.dryRun {
result := newPlannedRestoreResult(path, rev, opts)
return commandOutput(cmd).Render(func(w io.Writer) error {
return renderOperation(cmd, result.Input, []jsonOperationResult{restoreOperationResult(result)}, nil, func(w io.Writer) error {
return renderPlannedRestoreResult(w, result)
}, newJSONCommandOperationOutput(cmd, result.Input, []jsonOperationResult{restoreOperationResult(result)}, nil))
})
}

arg := files.NewRestoreArg(path, rev)
Expand Down
Loading