mirror of
https://github.com/octoleo/restic.git
synced 2024-11-21 20:35:12 +00:00
pass global context through cobra
This commit is contained in:
parent
49126796d0
commit
6d2d297215
@ -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() {
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user