-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(update): #23 add fossa update command #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary nits.
build/sbt.go
Outdated
@@ -144,10 +143,10 @@ func (builder *SBTBuilder) IsBuilt(m module.Module, allowUnresolved bool) (bool, | |||
|
|||
// IsModule is not implemented | |||
func (builder *SBTBuilder) IsModule(target string) (bool, error) { | |||
return false, errors.New("IsModule is not implemented for SBTBuilder") | |||
return false, fmt.Errorf("IsModule is not implemented for SBTBuilder") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to use fmt.Errorf
if you don't need the format string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be fixed. Also below, in the same file.
cmd/fossa/update.go
Outdated
var updateLogger = logging.MustGetLogger("update") | ||
var updateEndpoint := "fossas/fossa-cli" | ||
|
||
func checkUpdate() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return (bool, error)
. Don't use error
to represent things that are not errors.
cmd/fossa/update.go
Outdated
|
||
func updateCmd(c *cli.Context) { | ||
if err := checkUpdate(); err != nil { | ||
updateLogger.Fatalf("unable to update (%s)", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logged messages (distinct from error messages) should generally be Sentence case
. The reason why error messages should not be Sentence case
is because they're usually embedded within a sentence when they're finally logged to display to the user (e.g. logger.Fatalf("Problem happened: %s", err.Error())
).
cmd/fossa/update.go
Outdated
|
||
func updateCmd(c *cli.Context) { | ||
if err := checkUpdate(); err != nil { | ||
updateLogger.Fatalf("unable to update (%s)", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err
is of type error
. You probably mean err.Error()
, which is of type string
.
cmd/fossa/update.go
Outdated
|
||
func updateCmd(c *cli.Context) { | ||
if err := checkUpdate(); err != nil { | ||
updateLogger.Fatalf("unable to update (%s)", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the wrapping parentheses? Error messages should always be readable as conventional strings. If you need to display the value of the error
itself, you should use %#v
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes needed, but generally LGTM.
build/sbt.go
Outdated
@@ -144,10 +143,10 @@ func (builder *SBTBuilder) IsBuilt(m module.Module, allowUnresolved bool) (bool, | |||
|
|||
// IsModule is not implemented | |||
func (builder *SBTBuilder) IsModule(target string) (bool, error) { | |||
return false, errors.New("IsModule is not implemented for SBTBuilder") | |||
return false, fmt.Errorf("IsModule is not implemented for SBTBuilder") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be fixed. Also below, in the same file.
cmd/fossa/main.go
Outdated
@@ -244,6 +252,10 @@ func defaultCmd(c *cli.Context) { | |||
mainLogger.Fatalf("Could not load configuration: %s", err.Error()) | |||
} | |||
|
|||
if ok, err := checkUpdate(); ok && err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Would prefer err == nil && ok
. Generally, error checking goes first.
cmd/fossa/main.go
Outdated
@@ -244,6 +252,10 @@ func defaultCmd(c *cli.Context) { | |||
mainLogger.Fatalf("Could not load configuration: %s", err.Error()) | |||
} | |||
|
|||
if ok, err := checkUpdate(); ok && err == nil { | |||
mainLogger.Infof("An update is available for this CLI; run `fossa update` to get the latest version.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't actually log anything for most users. See logging levels from go-logging
:
const (
CRITICAL Level = iota
ERROR
WARNING
NOTICE
INFO
DEBUG
)
We currently only log WARNING
and above by default (see initialize
in config.go
). I'm alright with changing the default logging level to INFO
and above, although I'd actually consider this a NOTICE
.
cmd/fossa/update.go
Outdated
func checkUpdate() (bool, error) { | ||
latest, found, err := selfupdate.DetectLatest(updateEndpoint) | ||
if err != nil { | ||
return false, err // unable to update due to GH error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should annotate this error with fmt.Errorf
. For example, return false, fmt.Errorf("could not detect latest comment: %s", err.Error())
.
cmd/fossa/update.go
Outdated
} | ||
latest, err := selfupdate.UpdateSelf(v, updateEndpoint) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use fmt.Errorf
to annotate this error. It helps us trace errors through the stack.
65c24e9
to
23620d9
Compare
23620d9
to
29d496b
Compare
f342aa3
to
546d381
Compare
65e0fde
to
6300fa4
Compare
I'm merging this. I know it works, but our build is breaking because of backend issues causing our license check to fail. |
Uses
github.com/rhysd/go-github-selfupdate/selfupdate
to update binary.Not tested yet, do not merge.