How to use printUpdateInfo method of install Package

Best Gauge code snippet using install.printUpdateInfo

core.go

Source:core.go Github

copy

Full Screen

1// Copyright (c) 2019 abhijit wakchaure. All rights reserved.2// Use of this source code is governed by a MIT-style license3// that can be found in the LICENSE file.4// Package core implements methods that are essential to core operations of the app.5package core6import (7 "encoding/json"8 "fmt"9 "io/ioutil"10 "log"11 "net/http"12 "os"13 "path"14 "path/filepath"15 "regexp"16 "runtime"17 "sort"18 "strings"19 "github.com/abhijitWakchaure/run-flogo-app/utils"20)21// Constants for local env22const (23 AppName = "run-flogo-app"24 DefaultAppPatternLinux = `^.+-linux_amd64.*$`25 DefaultAppPatternWindows = `^.+-windows_amd64.*$`26 DefaultAppPatternDarwin = `^.+-darwin_amd64.*$`27 ConfigFile = "run-flogo-app.config"28 GithubLastestReleaseURL = "https://api.github.com/repos/abhijitWakchaure/run-flogo-app/releases/latest"29 GithubDownloadBaseURL = "https://github.com/abhijitWakchaure/run-flogo-app/releases/download/"30 GithubBaseURL = "https://github.com/abhijitWakchaure/run-flogo-app"31 GithubIssuesURL = "https://github.com/abhijitWakchaure/run-flogo-app/issues"32 CurrentAppVersion = "v1.5"33 InstallPathLinux = "/usr/local/bin"34 InstallPathDarwin = "/usr/local/bin"35 InstallPathWindows = `C:\Windows\system32`36)37// App holds the environment variables for the user38type App struct {39 _TempAppName string40 _InstallPath string41 _AppConfigPath string42 AppDir string `json:"appsDir" binding:"required"`43 AppPattern string `json:"appPattern"`44 IsUpdateAvailable bool `json:"isUpdateAvailable"`45 UpdateURL string `json:"updateURL"`46 ReleaseNotes string `json:"releaseNotes"`47}48// Init ...49func (a *App) Init() {50 if runtime.GOOS == "linux" {51 a._TempAppName = AppName + "-linux-amd64"52 a.AppPattern = DefaultAppPatternLinux53 a._InstallPath = InstallPathLinux54 } else if runtime.GOOS == "windows" {55 a._TempAppName = AppName + "-windows-amd64.exe"56 a.AppPattern = DefaultAppPatternWindows57 a._InstallPath = InstallPathWindows58 } else if runtime.GOOS == "darwin" {59 a._TempAppName = AppName + "-darwin-amd64"60 a.AppPattern = DefaultAppPatternDarwin61 a._InstallPath = InstallPathDarwin62 }63 a._AppConfigPath = path.Join(utils.GetUserHomeDir(), ConfigFile)64}65// ReadConfig will read the config from configuration file66func (a *App) ReadConfig() {67 fileExists, err := utils.CheckFileExists(a._AppConfigPath)68 if err != nil {69 log.Fatalln("# Error: ERR_READ_CONFIG", err)70 }71 if !fileExists {72 fmt.Print("#> Creating config file...")73 a.WriteConfig()74 return75 }76 f, err := ioutil.ReadFile(a._AppConfigPath)77 if err != nil {78 fmt.Println("#> Unable to read config...ignoring config...using defaults")79 a.loadDefaultConfig()80 return81 }82 err = json.Unmarshal(f, &a)83 if err != nil {84 fmt.Print("#> Invalid config detected...rewriting config...")85 a.WriteConfig()86 }87}88// WriteConfig will write the config into file89func (a *App) WriteConfig() {90 if a.AppDir == "" {91 a.loadDefaultConfig()92 }93 configJSON, _ := json.MarshalIndent(a, "", "\t")94 err := ioutil.WriteFile(a._AppConfigPath, configJSON, 0600)95 if err != nil {96 log.Fatalln("# Error: ERR_WRITE_CONFIG", err)97 }98 // fmt.Println("done")99}100func (a *App) loadDefaultConfig() {101 fmt.Print("loading default config...")102 a.AppDir = path.Join(utils.GetUserHomeDir(), "Downloads")103 fmt.Println("done")104}105func (a *App) validateConfig() {106 if a.AppDir == "" {107 fmt.Print("#> Invalid config detected...")108 a.WriteConfig()109 }110}111// FindLatestApp will return the latest flogo app name112func (a *App) FindLatestApp() string {113 files, err := ioutil.ReadDir(a.AppDir)114 if err != nil {115 log.Fatal(err)116 }117 sort.SliceStable(files, func(i, j int) bool {118 return files[i].ModTime().After(files[j].ModTime())119 })120 validApp := regexp.MustCompile(a.AppPattern)121 for _, f := range files {122 if !f.IsDir() && validApp.MatchString(f.Name()) {123 return path.Join(a.AppDir, f.Name())124 }125 }126 log.Println("#> Info: No flogo apps found in " + a.AppDir)127 return ""128}129// CheckForUpdates will check for latest release130func (a *App) CheckForUpdates() {131 resp, err := http.Get(GithubLastestReleaseURL)132 if err != nil {133 fmt.Println()134 log.Println("# Info: Unable to reach server for updates.")135 fmt.Println()136 return137 }138 defer resp.Body.Close()139 var gitdata map[string]interface{}140 err = json.NewDecoder(resp.Body).Decode(&gitdata)141 if err != nil {142 fmt.Println()143 log.Fatalln("# Error: ERR_CHKUPDATE_DECODE", err)144 log.Fatalln("# Request: Please create an issue here for this error:", GithubIssuesURL)145 }146 for _, d := range gitdata["assets"].([]interface{}) {147 durl := d.(map[string]interface{})["browser_download_url"].(string)148 if strings.Contains(durl, runtime.GOOS) && !strings.Contains(durl, CurrentAppVersion) {149 a.IsUpdateAvailable = true150 a.UpdateURL = durl151 a.ReleaseNotes = strings.Replace(strings.TrimSpace(gitdata["body"].(string)), "\n", "\n\t", -1)152 a.WriteConfig()153 return154 } else if strings.Contains(durl, runtime.GOOS) {155 fmt.Println()156 // fmt.Println("Your app is up to date 👍")157 return158 }159 }160}161// PrintUpdateInfo will print the update info162func (a *App) PrintUpdateInfo() {163 if a.IsUpdateAvailable {164 fmt.Println("#> New version of the app is available at:", a.UpdateURL)165 fmt.Println("#> Release Notes:")166 fmt.Printf("\t%s\n\n", a.ReleaseNotes)167 }168}169// Install will install the program170func (a *App) Install() {171 fmt.Print("#> Installing run-flogo-app...")172 ex, err := os.Executable()173 if err != nil {174 fmt.Println("failed")175 log.Fatalln("# Error: ERR_INSTALL_SELFPATH", err)176 }177 var src string178 var dst string179 if runtime.GOOS == "windows" {180 src = filepath.Dir(ex) + a._TempAppName181 dst = a._InstallPath + string(os.PathSeparator) + AppName + ".exe"182 } else {183 src = path.Join(filepath.Dir(ex), a._TempAppName)184 dst = path.Join(a._InstallPath, AppName)185 }186 err = utils.Copy(src, dst)187 if err != nil {188 fmt.Println("failed")189 log.Fatalln("# Error: ERR_INSTALL_COPY", err)190 }191 fmt.Println("done")192 fmt.Println("#> You can now directly execute ", AppName)193}194// Uninstall will install the program195func (a *App) Uninstall() {196 fmt.Println("#> Uninstalling run-flogo-app...")197 fmt.Print("...Deleting config file...")198 err := os.Remove(a._AppConfigPath)199 if err != nil {200 fmt.Println("failed")201 log.Println("# Error: ERR_UNINSTALL_CLRCONFIG", err)202 }203 fmt.Print("...Deleting main executable...")204 var target string205 if runtime.GOOS == "windows" {206 target = a._InstallPath + string(os.PathSeparator) + AppName + ".exe"207 } else {208 target = path.Join(a._InstallPath, AppName)209 }210 err = utils.Remove(target)211 if err != nil {212 fmt.Println("failed")213 fmt.Println("#> Unable to uninstall run-flogo-app...you can manually delete", path.Join(a._InstallPath, AppName))214 log.Fatalln("# Error: ERR_UNINSTALL_REMOVE", err)215 }216 fmt.Println()217 fmt.Println("#> Finished uninstalling run-flogo-app")218}219// Version ...220func (a *App) Version() {221 fmt.Println("## run-flogo-app")222 fmt.Println("#> Version:", CurrentAppVersion)223 fmt.Println("#> Developer: Abhijit Wakchaure")224 fmt.Println("#> Github:", GithubBaseURL)225}226// Main runs the core functions227func (a *App) Main() {228 go a.CheckForUpdates()229 a.ReadConfig()230 a.PrintUpdateInfo()231 a.validateConfig()232}...

Full Screen

Full Screen

check.go

Source:check.go Github

copy

Full Screen

...24 var wg sync.WaitGroup25 u.print = make(chan bool)26 u.wg = &wg27 u.wg.Add(1)28 go printUpdateInfo(u.print, u.wg)29}30func (u *UpdateFacade) PrintUpdateBuffer() {31 u.print <- true32 u.wg.Wait()33}34func PrintUpdateInfoWithDetails() {35 updates := checkUpdates()36 if len(updates) > 0 {37 for _, update := range updates {38 logger.Infof(true, fmt.Sprintf("%-10s\t\t%-10s\t%s", update.Name, update.CompatibleVersion, update.Message))39 }40 } else {41 logger.Infof(true, "No Updates available.")42 }43}44func checkUpdates() []UpdateInfo {45 return append(checkGaugeUpdate(), checkPluginUpdates()...)46}47func recoverPanic() {48 if r := recover(); r != nil {49 logger.Fatalf(true, "%v\n%s", r, string(debug.Stack()))50 }51}52func printUpdateInfo(print chan bool, wg *sync.WaitGroup) {53 message := make(chan string)54 go func() {55 defer recoverPanic()56 updates := checkUpdates()57 if len(updates) > 0 {58 message <- "Updates are available. Run `gauge update -c` for more info."59 }60 }()61 waitToPrint(message, print, "", wg)62}63func waitToPrint(messageChan chan string, printChan chan bool, message string, wg *sync.WaitGroup) {64 select {65 case <-printChan:66 if message != "" {...

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 i := install{}4 i.printUpdateInfo()5}6import (7func main() {8 i := install{}9 i.printUpdateInfo()10}11import (12func main() {13 i := install{}14 i.printUpdateInfo()15}16import (17func main() {18 i := install{}19 i.printUpdateInfo()20}21import (22func main() {23 i := install{}24 i.printUpdateInfo()25}26import (27func main() {28 i := install{}29 i.printUpdateInfo()30}31import (32func main() {33 i := install{}34 i.printUpdateInfo()35}36import (37func main() {38 i := install{}39 i.printUpdateInfo()40}41import (42func main() {43 i := install{}44 i.printUpdateInfo()45}46import (47func main() {48 i := install{}49 i.printUpdateInfo()50}51import (52func main() {53 i := install{}54 i.printUpdateInfo()55}

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4}5import "fmt"6func main() {7 fmt.Println("Hello World")8}9import "fmt"10func main() {11 fmt.Println("Hello World")12}13import "fmt"14func main() {15 fmt.Println("Hello World")16}17import "fmt"18func main() {19 fmt.Println("Hello World")20}21import "fmt"22func main() {23 fmt.Println("Hello World")24}25import "fmt"26func main() {27 fmt.Println("Hello World")28}29import "fmt"30func main() {31 fmt.Println("Hello World")32}33import "fmt"34func main() {35 fmt.Println("Hello World")36}37import "fmt"38func main() {39 fmt.Println("Hello World")40}41import "fmt"42func main() {43 fmt.Println("Hello World")44}45import "fmt"46func main() {47 fmt.Println("Hello World")48}49import "fmt"50func main() {51 fmt.Println("Hello World")52}53import

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 install.PrintUpdateInfo()5}6import "fmt"7func PrintUpdateInfo() {8 fmt.Println("This is a test")9}

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 install.PrintUpdateInfo()4 fmt.Println("Hello, playground")5}6import "fmt"7func PrintUpdateInfo() {8 fmt.Println("Update available")9}10 /usr/lib/go-1.14/src/install (from $GOROOT)11 /home/username/go/src/install (from $GOPATH)

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 install := install.NewInstall()4 install.PrintUpdateInfo()5}6import (7func main() {8 install := install.NewInstall()9 install.PrintUpdateInfo()10}11import (12func main() {13 install := install.NewInstall()14 install.PrintUpdateInfo()15}16import (17func main() {18 install := install.NewInstall()19 install.PrintUpdateInfo()20}21import (22func main() {23 install := install.NewInstall()24 install.PrintUpdateInfo()25}26import (27func main() {28 install := install.NewInstall()29 install.PrintUpdateInfo()30}31import (32func main() {33 install := install.NewInstall()34 install.PrintUpdateInfo()35}36import (37func main() {38 install := install.NewInstall()39 install.PrintUpdateInfo()40}41import (42func main() {43 install := install.NewInstall()44 install.PrintUpdateInfo()45}46import (47func main() {48 install := install.NewInstall()49 install.PrintUpdateInfo()50}

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1func main() {2 install := &Install{}3 install.printUpdateInfo()4}5func main() {6 install := &Install{}7 install.printUpdateInfo()8}9func main() {10 install := &Install{}11 install.printUpdateInfo()12}13func main() {14 install := &Install{}15 install.printUpdateInfo()16}17func main() {18 install := &Install{}19 install.printUpdateInfo()20}21func main() {22 install := &Install{}23 install.printUpdateInfo()24}25func main() {26 install := &Install{}27 install.printUpdateInfo()28}29func main() {30 install := &Install{}31 install.printUpdateInfo()32}33func main() {34 install := &Install{}35 install.printUpdateInfo()36}37func main() {38 install := &Install{}39 install.printUpdateInfo()40}41func main() {42 install := &Install{}43 install.printUpdateInfo()44}45func main() {46 install := &Install{}47 install.printUpdateInfo()48}49func main() {50 install := &Install{}51 install.printUpdateInfo()52}53func main() {54 install := &Install{}55 install.printUpdateInfo()56}57func main() {58 install := &Install{}59 install.printUpdateInfo()60}61func main() {62 install := &Install{}63 install.printUpdateInfo()64}

Full Screen

Full Screen

printUpdateInfo

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Using astaxie/beego/install package")4 install.PrintUpdateInfo()5}6import (7func main() {8 fmt.Println("Using astaxie/beego/install package")9 install.InstallPackage("github.com/astaxie/beego")10}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful