tsk-6: Added version package (#10)
Closes #6 Reviewed-on: #10 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
+16
-4
@@ -1,10 +1,11 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
"git.kundeng.us/phoenix/sender/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,6 +13,17 @@ const (
|
|||||||
App_Name = "sender"
|
App_Name = "sender"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func IsVersionFlagPresent() bool {
|
||||||
|
versionFlag := flag.Bool("version", false, "Print version information")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *versionFlag {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ParseConfig(filepath string) (config models.TwiloDetails, success bool) {
|
func ParseConfig(filepath string) (config models.TwiloDetails, success bool) {
|
||||||
content, err := os.ReadFile(filepath)
|
content, err := os.ReadFile(filepath)
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "flag"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/config"
|
"git.kundeng.us/phoenix/sender/config"
|
||||||
"git.kundeng.us/phoenix/sender/messaging"
|
"git.kundeng.us/phoenix/sender/messaging"
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
"git.kundeng.us/phoenix/sender/models"
|
||||||
"git.kundeng.us/phoenix/sender/util"
|
"git.kundeng.us/phoenix/sender/util"
|
||||||
// "git.kundeng.us/phoenix/sender/version"
|
"git.kundeng.us/phoenix/sender/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println(config.App_Name)
|
|
||||||
myArgs := os.Args
|
myArgs := os.Args
|
||||||
argCount := len(myArgs)
|
argCount := len(myArgs)
|
||||||
|
|
||||||
fmt.Printf("Argument count: %v\n", argCount)
|
if config.IsVersionFlagPresent() {
|
||||||
|
fmt.Println(config.App_Name)
|
||||||
if argCount < 4 {
|
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")
|
fmt.Println("Provide argument to config file and number file")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
@@ -29,16 +29,6 @@ func main() {
|
|||||||
|
|
||||||
fmt.Printf("Config file path: %s\n", configPath)
|
fmt.Printf("Config file path: %s\n", configPath)
|
||||||
|
|
||||||
// TODO: For version
|
|
||||||
/*
|
|
||||||
versionFlag := flag.Bool("version", false, "Print version information")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *versionFlag {
|
|
||||||
fmt.Println(version.String())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
cfg, _ := config.ParseConfig(configPath)
|
cfg, _ := config.ParseConfig(configPath)
|
||||||
|
|
||||||
cfg.PrintConfig()
|
cfg.PrintConfig()
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var (
|
||||||
|
Version = "dev"
|
||||||
|
BuildTime = "unknown"
|
||||||
|
Commit = "unknown"
|
||||||
|
GoVersion = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
func String() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"Version: %s\nBuild Date: %s\nCommit: %s\nGo Version: %s",
|
||||||
|
Version, BuildTime, Commit, GoVersion,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user