restic/src/cmds/restic/main.go

55 lines
1.1 KiB
Go
Raw Normal View History

2014-04-28 00:00:15 +02:00
package main
import (
2015-07-12 22:10:01 +02:00
"fmt"
"os"
"restic"
"restic/debug"
2016-09-17 12:36:05 +02:00
"github.com/spf13/cobra"
2016-09-01 22:17:37 +02:00
2016-09-17 12:36:05 +02:00
"restic/errors"
2014-04-28 00:00:15 +02:00
)
2016-09-17 12:36:05 +02:00
// cmdRoot is the base command when no other command has been specified.
var cmdRoot = &cobra.Command{
Use: "restic",
Short: "backup and restore files",
Long: `
restic is a backup program which allows saving multiple revisions of files and
directories in an encrypted repository stored on different backends.
`,
2017-01-02 19:14:22 +01:00
SilenceErrors: true,
SilenceUsage: true,
2017-01-22 19:10:32 +01:00
// run the debug functions for all subcommands (if build tag "debug" is
// enabled)
PersistentPreRunE: func(*cobra.Command, []string) error {
return runDebug()
},
PersistentPostRun: func(*cobra.Command, []string) {
shutdownDebug()
2017-01-22 19:10:32 +01:00
},
2016-09-17 12:36:05 +02:00
}
2014-04-28 00:00:15 +02:00
func main() {
2016-09-27 22:35:08 +02:00
debug.Log("main %#v", os.Args)
2016-09-17 12:36:05 +02:00
err := cmdRoot.Execute()
switch {
case restic.IsAlreadyLocked(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err)
2016-09-01 22:17:37 +02:00
case errors.IsFatal(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\n", err)
case err != nil:
2016-08-21 18:07:13 +02:00
fmt.Fprintf(os.Stderr, "%+v\n", err)
2016-01-17 16:59:03 +01:00
}
var exitCode int
2014-09-23 22:39:12 +02:00
if err != nil {
exitCode = 1
2014-04-28 00:00:15 +02:00
}
Exit(exitCode)
2014-04-28 00:00:15 +02:00
}