package main import ( "fmt" "github.com/edindazdarevic/confighub/chub/globals" "os" ) func main() { if len(os.Args[1:]) < 1 { usage() } 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) } } func usage() { fmt.Println("Configuration Hub v0.1") fmt.Println("") fmt.Println("Usage:") fmt.Println(" chub init - connects your server to the config hub machine id ") fmt.Println(" chub add /path/to/file.conf - starts tracking configuration file on that path") fmt.Println(" This 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) }