Fix usage error

pull/53/head v0.0.25
rwxrob 3 years ago
parent d821e800d4
commit 27523c3526
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -66,7 +66,7 @@ var ExeName string
// will be fetched from sumurl and used to validate the download before // will be fetched from sumurl and used to validate the download before
// making the replacement. For security reasons, no backup copy of the // making the replacement. For security reasons, no backup copy of the
// replaced executable is kept. Also see AutoUpdate. // replaced executable is kept. Also see AutoUpdate.
func ReplaceSelf(url, sumurl string) error { func ReplaceSelf(url, checksum string) error {
exe, err := os.Executable() exe, err := os.Executable()
if err != nil { if err != nil {
return err return err
@ -79,23 +79,17 @@ func ReplaceSelf(url, sumurl string) error {
return file.Replace(exe, url) return file.Replace(exe, url)
} }
// AutoUpdate automatically updates the current process executable (see // AutoUpdate automatically updates the current process executable
// Exe) by starting a goroutine that checks the current version against // version by starting a goroutine that checks the current semantic
// a remote one and calling ReplaceSelf if needed. // version (version) against a remote one (versurl) and calling
// ReplaceSelf with the URL of the binary (binurl) and checksum (sumurl)
// if and update is needed. Note that the binary will often be named
// quite differently than the name of the currently running executable
// (ex: foo-mac -> foo, foo-linux.
// //
// If cur is an int assumes it is an isosec (see uniq.IsoSecond) and // If a URL to a checksum file (sumurl) is not empty will optionally
// that newURL will return just a single line with an isosec in the body
// (usually a file named UPDATED).
//
// If cur is a string assumes it is a valid semantic version (beginning
// with a 'v') and will expect a single JSON string (don't forget the
// wrapping double-quotes) from newURL (usually in a file named VERSION)
// which will be compared using the Compare function from
// golang.org/x/mod/semver.
//
// If a URL to a checksum file (sum) is not empty will optionally
// validate the new version downloaded against the checksum before // validate the new version downloaded against the checksum before
// replace the currently running process executable with the new one. // replacing the currently running process executable with the new one.
// The format of the checksum file is the same as that output by any of // The format of the checksum file is the same as that output by any of
// the major checksum commands (sha512sum, for example) with one or more // the major checksum commands (sha512sum, for example) with one or more
// lines beginning with the checksum, whitespace, and then the name of // lines beginning with the checksum, whitespace, and then the name of
@ -103,12 +97,18 @@ func ReplaceSelf(url, sumurl string) error {
// but the most recent should always be at the top. When the update // but the most recent should always be at the top. When the update
// completes a message notifying of the update is logged to stderr. // completes a message notifying of the update is logged to stderr.
// //
// The function will fail silently under any of the following
// conditions:
//
// * current user does not have write access to executable
// * unable to establish a network connection
// * checksum provided does not match
//
// Since AutoUpdate happens in the background no return value is // Since AutoUpdate happens in the background no return value is
// provided. This means that failed Internet connections and other // provided. To enable logging of the update process (presumably for
// common reasons blocking the update silently fail. To enable logging // debugging) add the AutoUpdate flag to the Trace flags
// of the update process (presumably for debugging) add the AutoUpdate // (trace.Flags|=trace.AutoUpdate). Also see Cmd.AutoUpdate.
// flag to the Trace flags (trace.Flags|=trace.AutoUpdate). func AutoUpdate(version, versurl, binurl, sumurl string) {
func AutoUpdate[T int | string](cur T, newURL, sum, exe string) {
// TODO // TODO
} }

@ -114,7 +114,7 @@ func (x *Cmd) Run() {
// UsageError returns an error with a single-line usage string. // UsageError returns an error with a single-line usage string.
func (x *Cmd) UsageError() error { func (x *Cmd) UsageError() error {
return fmt.Errorf("usage: %v %v\n", x.Name, x.Usage) return fmt.Errorf("usage: %v %v", x.Name, x.Usage)
} }
// Unimplemented returns an error with a single-line usage string. // Unimplemented returns an error with a single-line usage string.

Loading…
Cancel
Save