Move command init into cmd_* files

This commit is contained in:
Alexander Neumann 2014-11-30 22:39:58 +01:00
parent bb8c52a974
commit 172b7bf123
8 changed files with 28 additions and 8 deletions

View File

@ -12,6 +12,10 @@ import (
"golang.org/x/crypto/ssh/terminal"
)
func init() {
commands["backup"] = commandBackup
}
func format_bytes(c uint64) string {
b := float64(c)

View File

@ -10,6 +10,10 @@ import (
"github.com/fd0/khepri/backend"
)
func init() {
commands["cat"] = commandCat
}
func commandCat(be backend.Server, key *khepri.Key, args []string) error {
if len(args) != 2 {
return errors.New("usage: cat [blob|tree|snapshot|key|lock] ID")

View File

@ -10,6 +10,10 @@ import (
"github.com/fd0/khepri/backend"
)
func init() {
commands["key"] = commandKey
}
func list_keys(be backend.Server, key *khepri.Key) error {
tab := NewTable()
tab.Header = fmt.Sprintf(" %-10s %-10s %-10s %s", "ID", "User", "Host", "Created")

View File

@ -8,6 +8,10 @@ import (
"github.com/fd0/khepri/backend"
)
func init() {
commands["list"] = commandList
}
func commandList(be backend.Server, key *khepri.Key, args []string) error {
if len(args) != 1 {
return errors.New("usage: list [data|trees|snapshots|keys|locks]")

View File

@ -10,6 +10,10 @@ import (
"github.com/fd0/khepri/backend"
)
func init() {
commands["ls"] = commandLs
}
func print_node(prefix string, n *khepri.Node) string {
switch n.Type {
case "file":

View File

@ -9,6 +9,10 @@ import (
"github.com/fd0/khepri/backend"
)
func init() {
commands["restore"] = commandRestore
}
func commandRestore(be backend.Server, key *khepri.Key, args []string) error {
if len(args) != 2 {
return errors.New("usage: restore ID dir")

View File

@ -72,6 +72,10 @@ func reltime(t time.Time) string {
}
}
func init() {
commands["snapshots"] = commandSnapshots
}
func commandSnapshots(be backend.Server, key *khepri.Key, args []string) error {
if len(args) != 0 {
return errors.New("usage: snapshots")

View File

@ -126,14 +126,6 @@ func create(u string) (backend.Server, error) {
}
func init() {
commands["backup"] = commandBackup
commands["restore"] = commandRestore
commands["list"] = commandList
commands["snapshots"] = commandSnapshots
commands["cat"] = commandCat
commands["ls"] = commandLs
commands["key"] = commandKey
// set GOMAXPROCS to number of CPUs
runtime.GOMAXPROCS(runtime.NumCPU())
}