2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-21 12:25:09 +00:00

pass global context through cobra

This commit is contained in:
Michael Eischer 2022-10-02 23:24:37 +02:00
parent 49126796d0
commit 6d2d297215
26 changed files with 26 additions and 30 deletions

View File

@ -57,7 +57,7 @@ Exit status is 3 if some source data could not be read (incomplete snapshot crea
},
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := globalCtx()
ctx := cmd.Context()
var wg sync.WaitGroup
cancelCtx, cancel := context.WithCancel(ctx)
defer func() {

View File

@ -25,7 +25,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runCat(globalCtx(), globalOptions, args)
return runCat(cmd.Context(), globalOptions, args)
},
}

View File

@ -35,7 +35,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runCheck(globalCtx(), checkOptions, globalOptions, args)
return runCheck(cmd.Context(), checkOptions, globalOptions, args)
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFlags(checkOptions)

View File

@ -32,7 +32,7 @@ This can be mitigated by the "--copy-chunker-params" option when initializing a
new destination repository using the "init" command.
`,
RunE: func(cmd *cobra.Command, args []string) error {
return runCopy(globalCtx(), copyOptions, globalOptions, args)
return runCopy(cmd.Context(), copyOptions, globalOptions, args)
},
}

View File

@ -46,7 +46,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runDebugDump(globalCtx(), globalOptions, args)
return runDebugDump(cmd.Context(), globalOptions, args)
},
}
@ -193,7 +193,7 @@ var cmdDebugExamine = &cobra.Command{
Short: "Examine a pack file",
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runDebugExamine(globalCtx(), globalOptions, args)
return runDebugExamine(cmd.Context(), globalOptions, args)
},
}

View File

@ -35,7 +35,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runDiff(globalCtx(), diffOptions, globalOptions, args)
return runDiff(cmd.Context(), diffOptions, globalOptions, args)
},
}

View File

@ -34,7 +34,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runDump(globalCtx(), dumpOptions, globalOptions, args)
return runDump(cmd.Context(), dumpOptions, globalOptions, args)
},
}

View File

@ -38,7 +38,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runFind(globalCtx(), findOptions, globalOptions, args)
return runFind(cmd.Context(), findOptions, globalOptions, args)
},
}

View File

@ -32,7 +32,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runForget(globalCtx(), forgetOptions, globalOptions, args)
return runForget(cmd.Context(), forgetOptions, globalOptions, args)
},
}

View File

@ -26,7 +26,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runInit(globalCtx(), initOptions, globalOptions, args)
return runInit(cmd.Context(), initOptions, globalOptions, args)
},
}

View File

@ -28,7 +28,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runKey(globalCtx(), globalOptions, args)
return runKey(cmd.Context(), globalOptions, args)
},
}

View File

@ -23,7 +23,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runList(globalCtx(), cmd, globalOptions, args)
return runList(cmd.Context(), cmd, globalOptions, args)
},
}

View File

@ -42,7 +42,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runLs(globalCtx(), lsOptions, globalOptions, args)
return runLs(cmd.Context(), lsOptions, globalOptions, args)
},
}

View File

@ -24,7 +24,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runMigrate(globalCtx(), migrateOptions, globalOptions, args)
return runMigrate(cmd.Context(), migrateOptions, globalOptions, args)
},
}

View File

@ -68,7 +68,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runMount(globalCtx(), mountOptions, globalOptions, args)
return runMount(cmd.Context(), mountOptions, globalOptions, args)
},
}

View File

@ -34,7 +34,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runPrune(globalCtx(), pruneOptions, globalOptions)
return runPrune(cmd.Context(), pruneOptions, globalOptions)
},
}

View File

@ -24,7 +24,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runRebuildIndex(globalCtx(), rebuildIndexOptions, globalOptions)
return runRebuildIndex(cmd.Context(), rebuildIndexOptions, globalOptions)
},
}

View File

@ -27,7 +27,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runRecover(globalCtx(), globalOptions)
return runRecover(cmd.Context(), globalOptions)
},
}

View File

@ -31,7 +31,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runRestore(globalCtx(), restoreOptions, globalOptions, args)
return runRestore(cmd.Context(), restoreOptions, globalOptions, args)
},
}

View File

@ -28,7 +28,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runSelfUpdate(globalCtx(), selfUpdateOptions, globalOptions, args)
return runSelfUpdate(cmd.Context(), selfUpdateOptions, globalOptions, args)
},
}

View File

@ -26,7 +26,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runSnapshots(globalCtx(), snapshotOptions, globalOptions, args)
return runSnapshots(cmd.Context(), snapshotOptions, globalOptions, args)
},
}

View File

@ -47,7 +47,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runStats(globalCtx(), globalOptions, args)
return runStats(cmd.Context(), globalOptions, args)
},
}

View File

@ -29,7 +29,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runTag(globalCtx(), tagOptions, globalOptions, args)
return runTag(cmd.Context(), tagOptions, globalOptions, args)
},
}

View File

@ -20,7 +20,7 @@ Exit status is 0 if the command was successful, and non-zero if there was any er
`,
DisableAutoGenTag: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runUnlock(globalCtx(), unlockOptions, globalOptions)
return runUnlock(cmd.Context(), unlockOptions, globalOptions)
},
}

View File

@ -145,10 +145,6 @@ func init() {
restoreTerminal()
}
func globalCtx() context.Context {
return internalGlobalCtx
}
// checkErrno returns nil when err is set to syscall.Errno(0), since this is no
// error condition.
func checkErrno(err error) error {

View File

@ -95,7 +95,7 @@ func main() {
debug.Log("main %#v", os.Args)
debug.Log("restic %s compiled with %v on %v/%v",
version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
err := cmdRoot.Execute()
err := cmdRoot.ExecuteContext(internalGlobalCtx)
switch {
case restic.IsAlreadyLocked(err):