cliupdater

module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2022 License: MIT

README

Cli Updater

A library to check for updates and update your CLI hosted on tools.getsip.ethz.ch.

Usage

Dependencies
  • Viper has to be set up.
home, err := os.UserHomeDir()
if err != nil {
    return fmt.Errorf("could not read user home directory: %v", err)
}
path := filepath.Join(home, ".config/vseth/<your_cli_name>")
filename := "cache"
filetype := "yaml"
viper.AddConfigPath(path)
viper.SetConfigName(filename)
viper.SetConfigType(filetype)
if err := viper.ReadInConfig(); err != nil {
    // assume a not found error and try to create the file
    if err := os.MkdirAll(path, 0744); err != nil {
        fmt.Printf("could not create path to config file: %v\n", err)
        os.Exit(1)
    }
    if err := ioutil.WriteFile(filepath.Join(path, filename+"."+filetype), []byte{}, 0644); err != nil {
        fmt.Printf("could not create config file: %v\n", err)
        os.Exit(1)
    }
}
How to use
import "gitlab.ethz.ch/vseth/0403-isg/libraries/cli-updater/updater"

// Use check when your CLI starts to check for updates, checks are only done
// once a day. The error returned by Check can be ignored (a user can still update manually).
updater.Check("<your tool name>");

// to allow manual updates use
if err := updater.Update(<your tool name>); err != nil {
    fmt.Printf("failed to update: %v", err)
}

In case of an update the method Check() will never return.

Features

  • includes caching and only checks every 24h
  • checks tools.getsip.ethz.ch///(.checksum) for an update

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL