-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
71 lines (57 loc) · 1.94 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/gosuri/uitable"
"vasanthdeveloper.com/samaya/constants"
"vasanthdeveloper.com/samaya/logger"
"github.com/spf13/cobra"
)
var arguments = constants.ArgumentSkeleton{}
var rootCmd = &cobra.Command{
Use: "samaya",
Short: "samaya",
Long: `samaya
A time synchronization program that uses HTTP protocol.`,
Run: start,
}
func main() {
rootCmd.Flags().BoolVarP(&arguments.Verbose, "verbose", "v", false, "Show extended output")
rootCmd.Flags().BoolVarP(&arguments.DryRun, "dry", "d", false, "Fetch the time, but don't update it")
rootCmd.Flags().BoolVarP(&arguments.Version, "version", "V", false, "Print the version number and exit")
rootCmd.Flags().IntVarP(&arguments.Delay, "delay", "D", 0, "Delay the number of seconds before requesting the time")
rootCmd.Flags().BoolVarP(&arguments.WaitForInternet, "wait for internet", "w", false, "Wait until an active internet connection is established")
rootCmd.Flags().StringVarP(&arguments.Timezone, "timezone", "t", "auto", "Set time of that timezone")
err := rootCmd.Execute()
if err != nil {
panic(err)
}
}
func start(cmd *cobra.Command, args []string) {
// This allows the logger to only log messages in verbose mode
logger.Arguments = arguments
logger.Build = Build
logger.Version = Version
// If the user passed the version flag, then show the version information
printVersion()
// Print the app name & version
logger.PrintApp()
// Start the start function
Start(arguments)
}
func printVersion() {
if arguments.Version == true {
table := uitable.New()
table.AddRow("Name:", "samaya")
table.AddRow("Version:", Version)
table.AddRow("License:", "GPL-v2.0")
table.AddRow("Build:", Build)
table.AddRow("Branch:", GitBranch)
table.AddRow("Commit:", CommitHash)
table.AddRow("Build By:", Username+"@"+Hostname)
table.AddRow("Build On:", BuildTime)
table.AddRow("Build Kernel:", BuildOS+" "+Kernel)
fmt.Println(table)
os.Exit(0)
}
}