checking for config file
This commit is contained in:
39
chub/main.go
39
chub/main.go
@@ -2,21 +2,41 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/edindazdarevic/confighub/chub/globals"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
if len(os.Args[1:]) < 2 {
|
||||
if len(os.Args[1:]) < 1 {
|
||||
usage()
|
||||
return
|
||||
}
|
||||
|
||||
command := os.Args[1]
|
||||
if command != "init" && !globals.FileExists(configurationFilePath()) {
|
||||
initializeFirst()
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
case command == "init":
|
||||
if len(os.Args[1:]) < 2 {
|
||||
usage()
|
||||
}
|
||||
machineId := os.Args[2]
|
||||
initCommand(machineId)
|
||||
|
||||
case command == "add":
|
||||
if len(os.Args[1:]) < 2 {
|
||||
usage()
|
||||
}
|
||||
pathToConfFile := os.Args[2]
|
||||
typeOfConfFile := "unknown"
|
||||
if len(os.Args[1:]) >= 3 {
|
||||
typeOfConfFile = os.Args[3]
|
||||
}
|
||||
addCommand(pathToConfFile, typeOfConfFile)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,5 +45,18 @@ func usage() {
|
||||
fmt.Println("Configuration Hub v0.1")
|
||||
fmt.Println("")
|
||||
fmt.Println("Usage:")
|
||||
fmt.Println("\tchub init <machine-uuid> - connects your server to the config hub machine id <machine-uiid>")
|
||||
fmt.Println(" chub init <machine-uuid> - connects your server to the config hub machine id <machine-uiid>")
|
||||
fmt.Println(" chub add /path/to/file.conf <type> - starts tracking configuration file on that path")
|
||||
fmt.Println(" This <type> thingy can be one of the following:\n")
|
||||
fmt.Println(" nginx\n elasticsearch\n")
|
||||
fmt.Println(" Or just leave it out and I will try to autodetect it (and sometimes fail)\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func initializeFirst() {
|
||||
fmt.Println("Configuration Hub v0.1")
|
||||
fmt.Println("")
|
||||
fmt.Println("There is no configuration file present. You need to run chub init first!")
|
||||
fmt.Printf("Checkout %v for details!\n", globals.WebSite)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user