ignore JSON flag for fully unsupported commands

Considering the flag would result in a mostly empty terminal output,
which is probably worse than text output instead of JSON.
This commit is contained in:
Michael Eischer
2025-09-21 15:38:26 +02:00
parent f71278138f
commit 2d7611373e
15 changed files with 16 additions and 16 deletions

View File

@@ -58,7 +58,7 @@ func (opts *CacheOptions) AddFlags(f *pflag.FlagSet) {
}
func runCache(opts CacheOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
if len(args) > 0 {
return errors.Fatal("the cache command expects no arguments, only options - please see `restic help cache` for usage and flags")

View File

@@ -70,7 +70,7 @@ func (opts *CopyOptions) AddFlags(f *pflag.FlagSet) {
}
func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
secondaryGopts, isFromRepo, err := fillSecondaryGlobalOpts(ctx, opts.secondaryRepoOptions, gopts, "destination", printer)
if err != nil {
return err

View File

@@ -188,7 +188,7 @@ func dumpIndexes(ctx context.Context, repo restic.ListerLoaderUnpacked, wr io.Wr
}
func runDebugDump(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
if len(args) != 1 {
return errors.Fatal("type not specified")
@@ -459,7 +459,7 @@ func storePlainBlob(id restic.ID, prefix string, plain []byte, printer progress.
}
func runDebugExamine(ctx context.Context, gopts GlobalOptions, opts DebugExamineOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
if opts.ExtractPack && gopts.NoLock {
return fmt.Errorf("--extract-pack and --no-lock are mutually exclusive")

View File

@@ -61,7 +61,7 @@ func runKeyAdd(ctx context.Context, gopts GlobalOptions, opts KeyAddOptions, arg
return fmt.Errorf("the key add command expects no arguments, only options - please see `restic help key add` for usage and flags")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithAppendLock(ctx, gopts, false, printer)
if err != nil {
return err

View File

@@ -56,7 +56,7 @@ func runKeyPasswd(ctx context.Context, gopts GlobalOptions, opts KeyPasswdOption
return fmt.Errorf("the key passwd command expects no arguments, only options - please see `restic help key passwd` for usage and flags")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
if err != nil {
return err

View File

@@ -45,7 +45,7 @@ Exit status is 12 if the password is incorrect.
}
func runList(ctx context.Context, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
if len(args) != 1 {
return errors.Fatal("type not specified")

View File

@@ -136,7 +136,7 @@ func applyMigrations(ctx context.Context, opts MigrateOptions, gopts GlobalOptio
}
func runMigrate(ctx context.Context, opts MigrateOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
if err != nil {

View File

@@ -116,7 +116,7 @@ func (opts *MountOptions) AddFlags(f *pflag.FlagSet) {
}
func runMount(ctx context.Context, opts MountOptions, gopts GlobalOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
if opts.TimeTemplate == "" {
return errors.Fatal("time template string cannot be empty")

View File

@@ -168,7 +168,7 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term
return errors.Fatal("--no-lock is only applicable in combination with --dry-run for prune command")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun && gopts.NoLock, printer)
if err != nil {
return err

View File

@@ -49,7 +49,7 @@ func runRecover(ctx context.Context, gopts GlobalOptions, term ui.Terminal) erro
return err
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
if err != nil {
return err

View File

@@ -73,7 +73,7 @@ func newRebuildIndexCommand() *cobra.Command {
}
func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
if err != nil {

View File

@@ -53,7 +53,7 @@ func runRepairPacks(ctx context.Context, gopts GlobalOptions, term ui.Terminal,
return errors.Fatal("no ids specified")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, false, printer)
if err != nil {

View File

@@ -76,7 +76,7 @@ func (opts *RepairOptions) AddFlags(f *pflag.FlagSet) {
}
func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOptions, args []string, term ui.Terminal) error {
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
ctx, repo, unlock, err := openWithExclusiveLock(ctx, gopts, opts.DryRun, printer)
if err != nil {

View File

@@ -296,7 +296,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a
return errors.Fatal("Nothing to do: no excludes provided and no new metadata provided")
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
var (
repo *repository.Repository

View File

@@ -88,7 +88,7 @@ func runSelfUpdate(ctx context.Context, opts SelfUpdateOptions, gopts GlobalOpti
}
}
printer := newTerminalProgressPrinter(gopts.JSON, gopts.verbosity, term)
printer := newTerminalProgressPrinter(false, gopts.verbosity, term)
printer.P("writing restic to %v", opts.Output)
v, err := selfupdate.DownloadLatestStableRelease(ctx, opts.Output, version, printer.P)