Reviewed-on: #13 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.kundeng.us/phoenix/sender/config"
|
|
"git.kundeng.us/phoenix/sender/messaging"
|
|
"git.kundeng.us/phoenix/sender/util"
|
|
"git.kundeng.us/phoenix/sender/version"
|
|
)
|
|
|
|
func main() {
|
|
myArgs := os.Args
|
|
argCount := len(myArgs)
|
|
|
|
if config.IsVersionFlagPresent() {
|
|
fmt.Println(config.App_Name)
|
|
fmt.Println(version.String())
|
|
return
|
|
} else if argCount < 4 {
|
|
fmt.Printf("Argument count: %v\n", argCount)
|
|
fmt.Println("Provide argument to config file and number file")
|
|
os.Exit(-1)
|
|
}
|
|
|
|
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
|
|
|
fmt.Printf("Config file path: %s\n", configPath)
|
|
fmt.Println("Numbers file path:", numberPath)
|
|
fmt.Println("Message path:", messagePath)
|
|
|
|
cfg, _ := config.ParseConfig(configPath)
|
|
cfg.PrintConfig()
|
|
|
|
numbers, err := util.ParseNumbers(numberPath)
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
return
|
|
}
|
|
|
|
prepMessage, err := util.ParseMessage(messagePath)
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
return
|
|
}
|
|
|
|
if len(numbers) == 0 || prepMessage.Content == "" {
|
|
if len(numbers) == 0 {
|
|
fmt.Println("No numbers to send")
|
|
os.Exit(-1)
|
|
} else {
|
|
fmt.Println("No message to send")
|
|
os.Exit(-1)
|
|
}
|
|
}
|
|
|
|
fmt.Println("")
|
|
fmt.Println("Message:", prepMessage.Content)
|
|
|
|
messaging.SendMessages(cfg, numbers, *prepMessage, 5)
|
|
}
|