| 41 | } |
| 42 | |
| 43 | func restore(cmd *cobra.Command, args []string) (err error) { |
| 44 | if len(args) != 2 { |
| 45 | return invalidArgumentsErrorWithDetails("`restore` requires `target-path` and `revision` arguments", argumentsErrorDetails("target-path", "revision")) |
| 46 | } |
| 47 | |
| 48 | path, err := validatePath(args[0]) |
| 49 | if err != nil { |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | rev := args[1] |
| 54 | |
| 55 | arg := files.NewRestoreArg(path, rev) |
| 56 | |
| 57 | dbx := filesNewFunc(config) |
| 58 | metadata, err := dbx.RestoreContext(currentContext(), arg) |
| 59 | if err != nil { |
| 60 | return withJSONErrorDetails(err, restoreErrorDetails(path, rev)) |
| 61 | } |
| 62 | |
| 63 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 64 | result, err := newRestoreResult(path, rev, metadata) |
| 65 | if err != nil { |
| 66 | return withJSONErrorDetails(err, restoreErrorDetails(path, rev)) |
| 67 | } |
| 68 | |
| 69 | return commandOutput(cmd).Render(func(w io.Writer) error { |
| 70 | if !verbose { |
| 71 | return nil |
| 72 | } |
| 73 | return renderRestoreResult(w, result) |
| 74 | }, newJSONCommandOperationOutput(cmd, result.Input, []jsonOperationResult{restoreOperationResult(result)}, nil)) |
| 75 | } |
| 76 | |
| 77 | func restoreErrorDetails(path, revision string) map[string]any { |
| 78 | return mergeJSONErrorDetails(operationErrorDetails("restore"), pathErrorDetails(path), revisionErrorDetails(revision)) |