Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
[[constraint]]
name = "github.com/dghubble/sling"
version = "1.1.0"

[[constraint]]
name = "github.com/italolelis/goupdater"
version = "0.1.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ github-cli [command] [--flags]
| `github-cli repo delete [--flags]` | Deletes a github repository |
| `github-cli hiring send [--flags]` | Creates a new hellofresh hiring test |
| `github-cli hiring unseat [--flags]` | Removes external collaborators from repositories |
| `github-cli update ` | Check for new versions of github-cli |
| `github-cli version` | Prints the version information |

## Contributing
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewRootCmd() *cobra.Command {
ctx := log.NewContext(context.Background())
ctx, err := config.NewContext(ctx, opts.configFile)
if err != nil {
log.WithContext(ctx).WithError(err).Error("Could not load configuration file")
log.WithContext(ctx).WithError(err).Fatal("Could not load configuration file")
}

cfg := config.WithContext(ctx)
Expand All @@ -66,6 +66,7 @@ func NewRootCmd() *cobra.Command {
cmd.AddCommand(NewRepoCmd(ctx))
cmd.AddCommand(NewHiringCmd(ctx))
cmd.AddCommand(NewVersionCmd(ctx))
cmd.AddCommand(NewUpdateCmd(ctx))

return &cmd
}
62 changes: 62 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cmd

import (
"context"
"fmt"

"github.com/hashicorp/errwrap"
"github.com/hellofresh/github-cli/pkg/log"
"github.com/italolelis/goupdater"
"github.com/spf13/cobra"
)

const (
githubOwner = "hellofresh"
githubRepo = "github-cli"
)

// UpdateOptions are the command flags
type UpdateOptions struct{}

// NewUpdateCmd creates a new update command
func NewUpdateCmd(ctx context.Context) *cobra.Command {
opts := &UpdateOptions{}

cmd := &cobra.Command{
Use: "update",
Aliases: []string{"self-update"},
Short: fmt.Sprintf("Check for new versions of %s", githubRepo),
RunE: func(cmd *cobra.Command, args []string) error {
return RunUpdate(ctx, opts)
},
}

return cmd
}

// RunUpdate runs the update command
func RunUpdate(ctx context.Context, opts *UpdateOptions) error {
logger := log.WithContext(ctx)
logger.Info("Checking if any new version is available...")

resolver, err := goupdater.NewGithubWithContext(ctx, goupdater.GithubOpts{
Owner: githubOwner,
Repo: githubRepo,
})
if err != nil {
return errwrap.Wrapf("could not create the updater client: {{err}}", err)
}

updated, err := goupdater.UpdateWithContext(ctx, resolver, version)
if err != nil {
return errwrap.Wrapf("could not update the binary: {{err}}", err)
}

if updated {
logger.Infof("You are now using the latest version of %s", githubRepo)
} else {
logger.Infof("You already have the latest version of %s", githubRepo)
}

return nil
}