-
Notifications
You must be signed in to change notification settings - Fork 10
/
init_include.go
53 lines (41 loc) · 1.02 KB
/
init_include.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
package command
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/simplesurance/baur/cfg"
"github.com/simplesurance/baur/log"
)
func init() {
initCmd.AddCommand(initIncludeCmd)
}
const defIncludeFilename = "includes.toml"
const initIncludeLongHelp = `
Create an include config file.
If no FILENAME argument is passed, the filename will be '` + defIncludeFilename + `'.`
var initIncludeCmd = &cobra.Command{
Use: "include [<FILENAME>]",
Short: "create an include config file",
Long: strings.TrimSpace(initIncludeLongHelp),
Run: initInclude,
Args: cobra.MaximumNArgs(1),
}
func initInclude(cmd *cobra.Command, args []string) {
var filename string
if len(args) == 1 {
filename = args[0]
} else {
filename = defIncludeFilename
}
cfg := cfg.ExampleInclude()
err := cfg.IncludeToFile(filename)
if err != nil {
if os.IsExist(err) {
log.Fatalf("%s already exist\n", filename)
}
log.Fatalln(err)
}
fmt.Printf("Include configuration file was written to %s\n",
highlight(filename))
}