Add method to create repository

Also disables automatic creation on open
This commit is contained in:
Alexander Neumann
2014-09-23 21:16:54 +02:00
parent f0287b2c9a
commit 03ca69407d
5 changed files with 145 additions and 35 deletions

20
cmd/khepri/cmd_init.go Normal file
View 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
}

View File

@@ -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:])