mirror of
https://github.com/restic/restic.git
synced 2025-12-10 05:31:49 +00:00
Add method to create repository
Also disables automatic creation on open
This commit is contained in:
20
cmd/khepri/cmd_init.go
Normal file
20
cmd/khepri/cmd_init.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fd0/khepri"
|
||||
)
|
||||
|
||||
func commandInit(path string) error {
|
||||
repo, err := khepri.CreateRepository(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "creating repository at %s failed: %v\n", path, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("created khepri repository at %s\n", repo.Path())
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -4,15 +4,13 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/fd0/khepri"
|
||||
"github.com/jessevdk/go-flags"
|
||||
)
|
||||
|
||||
var Opts struct {
|
||||
Repo string `short:"r" long:"repo" description:"Repository directory to backup to/restor from"`
|
||||
Repo string `short:"r" long:"repo" description:"Repository directory to backup to/restore from"`
|
||||
}
|
||||
|
||||
func errx(code int, format string, data ...interface{}) {
|
||||
@@ -50,18 +48,17 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
cmds := []string{}
|
||||
for k := range commands {
|
||||
cmds = append(cmds, k)
|
||||
}
|
||||
sort.Strings(cmds)
|
||||
fmt.Printf("nothing to do, available commands: [%v]\n", strings.Join(cmds, "|"))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
cmd := args[0]
|
||||
|
||||
if cmd == "init" {
|
||||
err = commandInit(Opts.Repo)
|
||||
if err != nil {
|
||||
errx(1, "error executing command %q: %v", cmd, err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
f, ok := commands[cmd]
|
||||
if !ok {
|
||||
errx(1, "unknown command: %q\n", cmd)
|
||||
@@ -70,7 +67,7 @@ func main() {
|
||||
repo, err := khepri.NewRepository(Opts.Repo)
|
||||
|
||||
if err != nil {
|
||||
errx(1, "unable to create/open repo: %v", err)
|
||||
errx(1, "unable to open repo: %v", err)
|
||||
}
|
||||
|
||||
err = f(repo, args[1:])
|
||||
|
||||
Reference in New Issue
Block a user