-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Please consider an enhancement to allow the Manager/Updater be created with a custom IsLatest function to be used internally in updater's CheckNow(). I did not see a way of doing so with the current version of selfupdate.
The purpose of this is that I wrote a custom github source, but I want to check strictly via semantic versioning. There are reasons why the mtime in an executable on disk might have changed and it can be a bad assumption for comparison. I also may have stricter rules that are independent of the Source Get logic.
I would suggest an IsLatest function signature to be something like this:
type IsLatestFunc func (current, available Version) (bool, error)
I also propose that the selfupdate.Manage function would take the above function or alternatively part of Config. Then the return updater internally will have all the state it needs to call the passed in IsLatest after the already extensible Get call on the Source.
If I could create a manager with this sig:
func ManageWithLatestCheck(conf *Config, isLatest IsLatestFunc) (*Updater, error)
Then I can do something like this:
...
updater := selfupdate.Manage(config,
func(c, a Version) (bool, error) {
cSem, err := NewSemVersion(c.Number)
if err != nil {
return false, fmt.Error("cannot parse semantic version from current")
}
aSem := NewSemVersion(a.Number)
if err != nil {
return false, fmt.Error("cannot parse semantic version from available")
}
return aSem.IsNewer(cSem), nil
})
...Alternatively, this custom function could be added into Config, but for some reason it feels awkward in there from my perspective, but whatever is fine.