aboutsummaryrefslogtreecommitdiff
path: root/storagecmd.go
blob: d2b603a9dbdc663ca6cc7fe7822177c0a4e8ffe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	"fmt"
	"os"
)

func StorageCmd(env *Env, args []string) int {
	cmds := env.Store.Subcmds()

	if len(args) == 0 {
		if len(cmds) == 0 {
			fmt.Fprintln(os.Stderr, "No storage subcommands available")
			return 2
		}

		fmt.Fprintln(os.Stderr, "Availabe storage subcommands:")
		for name := range cmds {
			fmt.Fprintln(os.Stderr, "  "+name)
		}
		return 2
	}

	cmd, ok := cmds[args[0]]
	if !ok {
		fmt.Fprintf(os.Stderr, "Unknown storage subcommand %s\n", args[0])
	}

	return cmd(args[1:], env.Log, env.Conf)
}