func beforeCommand(c *cli.Context) error { // set the env vars from global options if c.GlobalString("runenv") != "production" { tokenFile = "cx_" + c.GlobalString("runenv") + ".json" fmt.Printf(ansi.Color(fmt.Sprintf("Running against %s environment\n", c.GlobalString("runenv")), "grey")) honeybadger.Environment = c.GlobalString("runenv") } else { honeybadger.Environment = "production" } if c.GlobalString("fayeEndpoint") != "" { fayeEndpoint = c.GlobalString("fayeEndpoint") } debugMode = c.GlobalBool("debug") var command string if len(c.Args()) >= 1 { command = c.Args().First() } if (command != "version") && (command != "help") && (command != "update") { initClients(c) } if (command != "update") && (VERSION != "dev") { defer backgroundRun() } return nil }
func initClients(c *cli.Context) { // is there a token file? _, err := os.Stat(filepath.Join(cxHome(), tokenFile)) if err != nil { fmt.Println("No previous authentication found.") cloud66.Authorize(cxHome(), tokenFile) os.Exit(1) } else { client = cloud66.GetClient(cxHome(), tokenFile, VERSION) debugMode = c.GlobalBool("debug") client.Debug = debugMode } }
func runUpdate(c *cli.Context) { debugMode = c.GlobalBool("debug") flagForcedVersion = c.String("force") if debugMode { fmt.Printf("Current version is %s\n", VERSION) if flagForcedVersion == "" { fmt.Println("No forced version") } else { fmt.Printf("Forced version is %s\n", flagForcedVersion) } } updateIt, err := needUpdate() if err != nil { if debugMode { fmt.Printf("Cannot verify need for update %v\n", err) } return } if !updateIt { if debugMode { fmt.Println("No need for update") } return } // houston we have an update. which one do we need? download, err := getVersionManifest(flagForcedVersion) if err != nil { if debugMode { fmt.Printf("Error fetching manifest %v\n", err) } } if download == nil { if debugMode { fmt.Println("Found no matching download for the current OS and ARCH") } return } err = download.update() if err != nil { if debugMode { fmt.Printf("Failed to update: %v\n", err) } return } }