// NewUpdater constructor func NewUpdater(channel string) (*Updater, error) { serverVersion, err := getServerVersion(channel) if err != nil { return nil, err } return &Updater{ CurrentVersion: util.GetVersions(), ServerVersion: serverVersion, channel: channel, l: util.RootLogger().WithField("Logger", "Updater"), }, nil }
func cmdVersion(options *core.VersionOptions) error { logger := util.RootLogger().WithField("Logger", "Main") v := util.GetVersions() if options.OutputJSON { b, err := json.MarshalIndent(v, "", " ") if err != nil { logger.WithField("Error", err).Panic("Unable to marshal versions") } os.Stdout.Write(b) os.Stdout.WriteString("\n") return nil } logger.Infoln("Version:", v.Version) logger.Infoln("Compiled at:", v.CompiledAt.Local()) if v.GitCommit != "" { logger.Infoln("Git commit:", v.GitCommit) } if options.CheckForUpdate { channel := "stable" if options.BetaChannel { channel = "beta" } updater, err := NewUpdater(channel) if err != nil { return err } if updater.UpdateAvailable() { logger.Infoln("A new version is available:", updater.ServerVersion.FullVersion()) logger.Infoln("Download it from:", updater.DownloadURL()) if AskForUpdate() { if err := updater.Update(); err != nil { logger.WithField("Error", err).Warn( "Unable to download latest version. Please try again.") return err } } } else { logger.Infoln("No new version available") } } return nil }
// NewMetricsHandler will create a new NewMetricsHandler. func NewMetricsHandler(opts *core.PipelineOptions) (*MetricsEventHandler, error) { if "" == opts.KeenProjectWriteKey { return nil, errors.New("No KeenProjectWriteKey specified") } if "" == opts.KeenProjectID { return nil, errors.New("No KeenProjectID specified") } keenInstance := &keen.Client{ WriteKey: opts.KeenProjectWriteKey, ProjectID: opts.KeenProjectID, } versions := util.GetVersions() return &MetricsEventHandler{ keen: keenInstance, versions: versions, startStep: make(map[string]time.Time), }, nil }
func cmdVersion(options *core.VersionOptions) error { logger := util.RootLogger().WithField("Logger", "Main") v := util.GetVersions() if options.OutputJSON { b, err := json.MarshalIndent(v, "", " ") if err != nil { logger.WithField("Error", err).Panic("Unable to marshal versions") } os.Stdout.Write(b) os.Stdout.WriteString("\n") return nil } logger.Infoln("Version:", v.Version) logger.Infoln("Compiled at:", v.CompiledAt.Local()) if v.GitCommit != "" { logger.Infoln("Git commit:", v.GitCommit) } if options.CheckForUpdate { channel := "stable" if options.BetaChannel { channel = "beta" } updater, err := NewUpdater(channel) if err != nil { return err } if updater.UpdateAvailable() { logger.Infoln("A new version is available:", updater.ServerVersion.FullVersion()) // try to determine if binary was installed with homebrew homebrew := util.InstalledWithHomebrew() if homebrew { logger.Info("\nLooks like wercker was installed with homebrew.\n\n" + "To update to the latest version please use:\n" + "brew update && brew upgrade wercker-cli") logger.Println("\nUsing the built in updater can cause issues with Wercker installed with homebrew.") } else { logger.Infoln("Download it from:", updater.DownloadURL()) } if AskForUpdate() { if err := updater.Update(); err != nil { logger.WithField("Error", err).Warn( "Unable to download latest version. Please try again.") return err } } } else { logger.Infoln("No new version available") } } return nil }