Skip to content
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

Merged
merged 12 commits into from
Feb 23, 2018
Merged

Conversation

xizhao
Copy link
Contributor

@xizhao xizhao commented Feb 20, 2018

Uses github.com/rhysd/go-github-selfupdate/selfupdate to update binary.

Not tested yet, do not merge.

Copy link
Member

@elldritch elldritch left a 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")
Copy link
Member

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.

Copy link
Member

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.

var updateLogger = logging.MustGetLogger("update")
var updateEndpoint := "fossas/fossa-cli"

func checkUpdate() error {
Copy link
Member

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.


func updateCmd(c *cli.Context) {
if err := checkUpdate(); err != nil {
updateLogger.Fatalf("unable to update (%s)", err)
Copy link
Member

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())).


func updateCmd(c *cli.Context) {
if err := checkUpdate(); err != nil {
updateLogger.Fatalf("unable to update (%s)", err)
Copy link
Member

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.


func updateCmd(c *cli.Context) {
if err := checkUpdate(); err != nil {
updateLogger.Fatalf("unable to update (%s)", err)
Copy link
Member

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.

Copy link
Member

@elldritch elldritch left a 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")
Copy link
Member

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.

@@ -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 {
Copy link
Member

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.

@@ -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.")
Copy link
Member

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.

func checkUpdate() (bool, error) {
latest, found, err := selfupdate.DetectLatest(updateEndpoint)
if err != nil {
return false, err // unable to update due to GH error
Copy link
Member

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()).

}
latest, err := selfupdate.UpdateSelf(v, updateEndpoint)
if err != nil {
return err
Copy link
Member

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.

@elldritch elldritch force-pushed the feat/selfupdate branch 2 times, most recently from 65c24e9 to 23620d9 Compare February 23, 2018 02:33
@elldritch
Copy link
Member

I'm merging this. I know it works, but our build is breaking because of backend issues causing our license check to fail.

@elldritch elldritch merged commit ec4e164 into master Feb 23, 2018
@elldritch elldritch deleted the feat/selfupdate branch March 1, 2018 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants