-
Notifications
You must be signed in to change notification settings - Fork 25
/
config.go
59 lines (51 loc) · 1.05 KB
/
config.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
52
53
54
55
56
57
58
59
/*
Copyright (C) CESS. All rights reserved.
Copyright (C) Cumulus Encrypted Storage System. All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package console
import (
"os"
"path/filepath"
"github.com/CESSProject/cess-bucket/pkg/confile"
"github.com/CESSProject/p2p-go/out"
"github.com/spf13/cobra"
)
const init_cmd = "config"
var initCmd = &cobra.Command{
Use: init_cmd,
Short: "Generate configuration file",
Run: func(cmd *cobra.Command, args []string) {
CreateConfigFile()
return
},
DisableFlagsInUseLine: true,
}
func init() {
rootCmd.AddCommand(initCmd)
}
// Create a configuration file template
func CreateConfigFile() {
f, err := os.Create(confile.DefaultProfile)
if err != nil {
out.Err(err.Error())
return
}
defer f.Close()
_, err = f.WriteString(confile.TempleteProfile)
if err != nil {
out.Err(err.Error())
return
}
err = f.Sync()
if err != nil {
out.Err(err.Error())
return
}
pwd, err := os.Getwd()
if err != nil {
out.Err(err.Error())
return
}
out.Ok(filepath.Join(pwd, confile.DefaultProfile))
}