-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.go
85 lines (69 loc) · 2.73 KB
/
entrypoint.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
"context"
"fmt"
"os"
"github.com/kaz-under-the-bridge/mock-alert-notifier/internal/helper"
"github.com/spf13/cobra"
)
var ctx context.Context
func init() {
ctx = context.Background()
// get logType from global flag
RootCmd.PersistentFlags().StringVar(&globalVarLogType, "log-type", "stdout", "stdout or file")
// get logFile from global flag
RootCmd.PersistentFlags().StringVar(&globalVarLogFile, "log-file", "", "path to log file")
// get logFormat from global flag
RootCmd.PersistentFlags().StringVar(&globalVarLogFormat, "log-format", "text", "text or json")
// SMS Command Tree
RootCmd.AddCommand(SMSCmd)
SMSCmd.AddCommand(SMSSendCmd)
SMSSendCmd.Flags().BoolVar(&SMSSendAll, "send-to-all", false, "ユーザー台帳全員へSMS送信を行う")
SMSSendCmd.Flags().StringVar(&SMSSendUserByIDs, "ids", "", "カンマ区切りの指定IDリストのユーザーにのみSMS送信を行う ※send-to-allより優先されます")
SMSSendCmd.Flags().StringVar(&SMSTemplateName, "template-name", "", "送信に使用するテンプレート名(nameフィールドの値)を指定, templates/sms/template.yamlを使用")
// Voice Command Tree
RootCmd.AddCommand(VoiceCmd)
VoiceCmd.AddCommand(VoiceCallCmd)
VoiceCallCmd.Flags().BoolVar(&VoiceCallAll, "call-to-all", false, "ユーザ台帳全員へ電話発信を行う")
VoiceCallCmd.Flags().StringVar(&VoiceCallUserByIDs, "ids", "", "カンマ区切りの指定IDリストのユーザーにのみSMS送信を行う ※call-to-allより優先されます")
VoiceCallCmd.Flags().StringVar(&VoiceCallURL, "voice-data-url", "", "送信時に使用するデーターのURLを指定する ※必須")
setBasicConfigTo(ctx)
}
var Version = "1.0"
var Revision = "00"
var globalVarLogType string
var globalVarLogFile string
var globalVarLogFormat string
var rootVersion bool
var RootCmd = &cobra.Command{
Use: "mock-alert-notifier",
Short: "mock alert notifier",
Run: func(cmd *cobra.Command, args []string) {
if rootVersion {
fmt.Printf("version: %s-%s\n", Version, Revision)
os.Exit(0)
}
_ = cmd.Help()
},
}
// function to set basic configration to ctx for appName, logType, logFile, logFormat
func setBasicConfigTo(ctx context.Context) context.Context {
// get logType from global flag
logType := globalVarLogType
// get logFile from global flag
logFile := globalVarLogFile
// get logFormat from global flag
logFormat := globalVarLogFormat
// set basic configration to ctx
helper.SetAppName(ctx, "mock-alert-notifier")
helper.SetLogType(ctx, logType)
if logType == "file" {
if logFile == "" {
fmt.Println("log-file is empty, please set log-file path")
os.Exit(1)
}
helper.SetLogFile(ctx, logFile)
}
helper.SetLogFormat(ctx, logFormat)
return ctx
}