refactor: tidy the command's setup, the update command and instance reach (#73)
- main: the subcommand is a name rather than nil-or-empty argument slices; the cache file and start directory are worked out once; config values with a default go through one valueOr helper. - The link handler's --config argument comes from one configArgs helper. - lazysecrets update parses its flags like the other subcommands, so -check and --check=true work too, and tells a development build by its dev version. - Instance reach is named (unreachable, switchable, inView), tmux client activity is compared as a number, and the best client loop starts from the first. - update: serverTimeout (it bounds the checksums request too), and parentheses in the platform check. Reviewed-on: #73 Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
This commit was merged in pull request #73.
This commit is contained in:
1 parent
fae8e1cbb4
commit
6842c72662
7 files changed
+105
-114
No files matched your search
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -32,8 +33,12 @@ func updater(servers []string) *app.Updater {
|
||||
// updateCmd is lazysecrets update [--check]: the newer release's
|
||||
// changelog, then (unless --check) install it.
|
||||
func updateCmd(configPath string, args []string) error {
|
||||
check := len(args) == 1 && args[0] == "--check"
|
||||
if len(args) > 0 && !check {
|
||||
fs := flag.NewFlagSet("update", flag.ContinueOnError)
|
||||
check := fs.Bool("check", false, "just say if there's a newer release")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if fs.NArg() != 0 {
|
||||
return errors.New("usage: lazysecrets update [--check]")
|
||||
}
|
||||
cfg, err := config.LoadAll(strings.Split(configPath, ","))
|
||||
@@ -49,14 +54,14 @@ func updateCmd(configPath string, args []string) error {
|
||||
return fmt.Errorf("looking for a newer lazysecrets: %w", err)
|
||||
}
|
||||
if !update.Newer(current, r.Tag) {
|
||||
if !update.Newer(current, "v999.0.0") {
|
||||
if strings.HasPrefix(current, "dev") {
|
||||
return fmt.Errorf("this is a development build (%s); the latest release is %s: install it with install.sh, or go install …@%s", current, r.Tag, r.Tag)
|
||||
}
|
||||
fmt.Printf("lazysecrets %s is the latest (%s)\n", current, r.Tag)
|
||||
return nil
|
||||
}
|
||||
fmt.Printf("lazysecrets %s is out (you have %s):\n\n%s\n\n", r.Tag, current, indent(r.Notes(current)))
|
||||
if check {
|
||||
if *check {
|
||||
fmt.Println("lazysecrets update installs it.")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user