From 3c45833304260027b447f474b3c47d3807469fd4 Mon Sep 17 00:00:00 2001 From: Soulou Date: Thu, 5 Jul 2018 11:03:52 +0200 Subject: [PATCH] Add a way to disable update checker making an http request Fixes #361 --- README.md | 9 +++++++++ config/config.go | 27 ++++++++++++++------------- update/check.go | 11 ++++++++++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 09995d73e..4c8abc444 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,15 @@ http_proxy=http://: https_proxy=https://: ``` +## Disable update checking + +By default the CLI is making an HTTP request to learn if a newer version is available. +To disable this feature, define the environment variable: + +``` +DISABLE_UPDATE_CHECKER=true +``` + ## Command help ``` diff --git a/config/config.go b/config/config.go index 7a30c4a0c..2edd6cabc 100644 --- a/config/config.go +++ b/config/config.go @@ -16,19 +16,20 @@ import ( ) type Config struct { - ScalingoApiUrl string - apiHost string - TokenGenerator scalingo.TokenGenerator - ApiVersion string - DisableInteractive bool - SshHost string - UnsecureSsl bool - RollbarToken string - ConfigDir string - AuthFile string - LogFile string - logFile *os.File - Logger *log.Logger + ScalingoApiUrl string + apiHost string + TokenGenerator scalingo.TokenGenerator + ApiVersion string + DisableInteractive bool + DisableUpdateChecker bool + SshHost string + UnsecureSsl bool + RollbarToken string + ConfigDir string + AuthFile string + LogFile string + logFile *os.File + Logger *log.Logger } var ( diff --git a/update/check.go b/update/check.go index fd8a9605f..6c2e3eceb 100644 --- a/update/check.go +++ b/update/check.go @@ -15,11 +15,16 @@ import ( var ( lastVersionURL = "https://cli-dl.scalingo.io/version" lastVersion = "" + cancelUpdate = make(chan struct{}) gotLastVersion = make(chan struct{}) gotAnError = false ) func init() { + if config.C.DisableUpdateChecker { + close(cancelUpdate) + return + } go func() { var err error lastVersion, err = getLastVersion() @@ -39,7 +44,11 @@ func Check() error { return nil } - <-gotLastVersion + select { + case <-cancelUpdate: + return nil + case <-gotLastVersion: + } if gotAnError { return errgo.New("Update checker: connection error")