-
Notifications
You must be signed in to change notification settings - Fork 1
/
add.go
51 lines (40 loc) · 827 Bytes
/
add.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package profile
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/juliengk/go-utils"
"github.com/kassisol/metadata/api/storage"
"github.com/kassisol/metadata/pkg/adf"
"github.com/spf13/cobra"
)
func newAddCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "add [name]",
Short: "Add profile",
Long: addDescription,
Run: runAdd,
}
return cmd
}
func runAdd(cmd *cobra.Command, args []string) {
defer utils.RecoverFunc()
if len(args) < 1 || len(args) > 1 {
cmd.Usage()
os.Exit(-1)
}
cfg := adf.NewDaemon()
if err := cfg.Init(); err != nil {
log.Fatal(err)
}
s, err := storage.NewDriver("sqlite", cfg.App.Dir.Root)
if err != nil {
log.Fatal(err)
}
defer s.End()
if err := s.AddProfile(args[0]); err != nil {
log.Fatal(err)
}
}
var addDescription = `
Add profile
`