(globalOptions *global.Options)
| 25 | ) |
| 26 | |
| 27 | func newCheckCommand(globalOptions *global.Options) *cobra.Command { |
| 28 | var opts CheckOptions |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "check [flags]", |
| 31 | Short: "Check the repository for errors", |
| 32 | Long: ` |
| 33 | The "check" command tests the repository for errors and reports any errors it |
| 34 | finds. |
| 35 | |
| 36 | By default, check verifies the structural consistency and integrity of |
| 37 | snapshots, trees and pack files. To also verify the integrity of the actual |
| 38 | backed-up data, use the --read-data or --read-data-subset flags. |
| 39 | |
| 40 | By default, check creates a new temporary cache directory to verify data. |
| 41 | To reuse the existing cache, use the --with-cache flag. |
| 42 | |
| 43 | EXIT STATUS |
| 44 | =========== |
| 45 | |
| 46 | Exit status is 0 if the command was successful. |
| 47 | Exit status is 1 if there was any error. |
| 48 | Exit status is 10 if the repository does not exist. |
| 49 | Exit status is 11 if the repository is already locked. |
| 50 | Exit status is 12 if the password is incorrect. |
| 51 | `, |
| 52 | GroupID: cmdGroupDefault, |
| 53 | DisableAutoGenTag: true, |
| 54 | RunE: func(cmd *cobra.Command, args []string) error { |
| 55 | finalizeSnapshotFilter(&opts.SnapshotFilter) |
| 56 | summary, err := runCheck(cmd.Context(), opts, *globalOptions, args, globalOptions.Term) |
| 57 | if globalOptions.JSON { |
| 58 | if err != nil && summary.NumErrors == 0 { |
| 59 | summary.NumErrors = 1 |
| 60 | } |
| 61 | globalOptions.Term.Print(ui.ToJSONString(summary)) |
| 62 | } |
| 63 | return err |
| 64 | }, |
| 65 | PreRunE: func(_ *cobra.Command, _ []string) error { |
| 66 | return checkFlags(opts) |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | opts.AddFlags(cmd.Flags()) |
| 71 | return cmd |
| 72 | } |
| 73 | |
| 74 | // CheckOptions bundles all options for the 'check' command. |
| 75 | type CheckOptions struct { |
no test coverage detected