Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RELEASE_CHANGELOG.md
**/Cargo.lock
!pkg/commands/compute/testdata/build/rust/Cargo.lock
**/*.tar.gz
!pkg/github/testdata/*.tar.gz
!pkg/commands/compute/testdata/deploy/pkg/package.tar.gz
!pkg/commands/update/testdata/fastly_v0.41.0_darwin-amd64.tar.gz
**/bin
**/src
!pkg/commands/compute/testdata/build/rust/src
Expand Down
6 changes: 3 additions & 3 deletions cmd/fastly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"time"

"github.com/fastly/cli/pkg/app"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/config"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/revision"
"github.com/fastly/cli/pkg/sync"
"github.com/fatih/color"
Expand Down Expand Up @@ -66,12 +66,12 @@ func main() {
httpClient = &http.Client{Timeout: time.Second * 5}
in io.Reader = os.Stdin
out io.Writer = sync.NewWriter(color.Output)
versionerCLI = update.NewGitHub(update.GitHubOpts{
versionerCLI = github.New(github.Opts{
Org: "fastly",
Repo: "cli",
Binary: "fastly",
})
versionerViceroy = update.NewGitHub(update.GitHubOpts{
versionerViceroy = github.New(github.Opts{
Org: "fastly",
Repo: "viceroy",
Binary: "viceroy",
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/env"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/profile"
"github.com/fastly/cli/pkg/revision"
Expand All @@ -24,8 +25,8 @@ import (

// Versioners represents all supported versioner types.
type Versioners struct {
CLI update.Versioner
Viceroy update.Versioner
CLI github.Versioner
Viceroy github.Versioner
}

// RunOpts represent arguments to Run()
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/compute/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/fastly/cli/pkg/commands/compute"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/testutil"
"github.com/fastly/kingpin"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestServeFlagDivergence(t *testing.T) {
cfg config.Data
data manifest.Data
)
versioner := update.NewGitHub(update.GitHubOpts{
versioner := github.New(github.Opts{
Org: "fastly",
Repo: "viceroy",
Binary: "viceroy",
Expand Down
14 changes: 7 additions & 7 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/blang/semver"
"github.com/fastly/cli/pkg/check"
"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/config"
fsterr "github.com/fastly/cli/pkg/errors"
fstexec "github.com/fastly/cli/pkg/exec"
"github.com/fastly/cli/pkg/filesystem"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fatih/color"
Expand All @@ -36,7 +36,7 @@ type ServeCommand struct {
cmd.Base
manifest manifest.Data
build *BuildCommand
viceroyVersioner update.Versioner
viceroyVersioner github.Versioner

// Build fields
includeSrc cmd.OptionalBool
Expand All @@ -55,7 +55,7 @@ type ServeCommand struct {
}

// NewServeCommand returns a usable command registered under the parent.
func NewServeCommand(parent cmd.Registerer, globals *config.Data, build *BuildCommand, viceroyVersioner update.Versioner, data manifest.Data) *ServeCommand {
func NewServeCommand(parent cmd.Registerer, globals *config.Data, build *BuildCommand, viceroyVersioner github.Versioner, data manifest.Data) *ServeCommand {
var c ServeCommand

c.build = build
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *ServeCommand) Build(in io.Reader, out io.Writer) error {
//
// In the case of a network failure we fallback to the latest installed version of the
// Viceroy binary as long as one is installed and has the correct permissions.
func GetViceroy(progress text.Progress, out io.Writer, versioner update.Versioner, cfg *config.Data) (bin string, err error) {
func GetViceroy(progress text.Progress, out io.Writer, versioner github.Versioner, cfg *config.Data) (bin string, err error) {
defer func() {
if err != nil {
progress.Fail()
Expand Down Expand Up @@ -243,7 +243,7 @@ func GetViceroy(progress text.Progress, out io.Writer, versioner update.Versione
}

archiveFormat := ".tar.gz"
asset := fmt.Sprintf(update.DefaultAssetFormat, versioner.BinaryName(), latest, runtime.GOOS, runtime.GOARCH, archiveFormat)
asset := fmt.Sprintf(github.DefaultAssetFormat, versioner.BinaryName(), latest, runtime.GOOS, runtime.GOARCH, archiveFormat)
versioner.SetAsset(asset)

if install {
Expand Down Expand Up @@ -286,7 +286,7 @@ var InstallDir = func() string {
}()

// installViceroy downloads the latest release from GitHub.
func installViceroy(progress text.Progress, versioner update.Versioner, latest semver.Version, bin string) error {
func installViceroy(progress text.Progress, versioner github.Versioner, latest semver.Version, bin string) error {
progress.Step("Fetching latest Viceroy release...")

tmp, err := versioner.Download(context.Background(), latest)
Expand All @@ -308,7 +308,7 @@ func installViceroy(progress text.Progress, versioner update.Versioner, latest s

// updateViceroy checks if the currently installed version is out-of-date and
// downloads the latest release from GitHub.
func updateViceroy(progress text.Progress, version string, out io.Writer, versioner update.Versioner, latest semver.Version, bin string) error {
func updateViceroy(progress text.Progress, version string, out io.Writer, versioner github.Versioner, latest semver.Version, bin string) error {
progress.Step("Checking installed Viceroy version...")

var installedViceroyVersion string
Expand Down
7 changes: 4 additions & 3 deletions pkg/commands/update/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"strings"

"github.com/blang/semver"
"github.com/fastly/cli/pkg/github"
fstruntime "github.com/fastly/cli/pkg/runtime"
)

// Check if the CLI can be updated.
func Check(ctx context.Context, currentVersion string, cliVersioner Versioner) (current, latest semver.Version, shouldUpdate bool) {
func Check(ctx context.Context, currentVersion string, cliVersioner github.Versioner) (current, latest semver.Version, shouldUpdate bool) {
current, err := semver.Parse(strings.TrimPrefix(currentVersion, "v"))
if err != nil {
return current, latest, false
Expand All @@ -28,7 +29,7 @@ func Check(ctx context.Context, currentVersion string, cliVersioner Versioner) (
if fstruntime.Windows {
archiveFormat = ".zip"
}
asset := fmt.Sprintf(DefaultAssetFormat, cliVersioner.BinaryName(), latest, runtime.GOOS, runtime.GOARCH, archiveFormat)
asset := fmt.Sprintf(github.DefaultAssetFormat, cliVersioner.BinaryName(), latest, runtime.GOOS, runtime.GOARCH, archiveFormat)
cliVersioner.SetAsset(asset)

return current, latest, latest.GT(current)
Expand All @@ -53,7 +54,7 @@ type checkResult struct {
func CheckAsync(
ctx context.Context,
currentVersion string,
cliVersioner Versioner,
cliVersioner github.Versioner,
quietMode bool,
) (printResults func(io.Writer)) {
results := make(chan checkResult, 1)
Expand Down
5 changes: 3 additions & 2 deletions pkg/commands/update/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/blang/semver"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/mock"
"github.com/google/go-cmp/cmp"
)
Expand All @@ -20,7 +21,7 @@ func TestCheck(t *testing.T) {
for _, testcase := range []struct {
name string
current string
latest update.Versioner
latest github.Versioner
wantCurrent semver.Version
wantLatest semver.Version
wantUpdate bool
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestCheckAsync(t *testing.T) {
name string
file config.File
currentVersion string
cliVersioner update.Versioner
cliVersioner github.Versioner
wantOutput string
}{
{
Expand Down
5 changes: 3 additions & 2 deletions pkg/commands/update/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/filesystem"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/revision"
fstruntime "github.com/fastly/cli/pkg/runtime"
"github.com/fastly/cli/pkg/text"
Expand All @@ -19,12 +20,12 @@ import (
// It should be installed under the primary root command.
type RootCommand struct {
cmd.Base
cliVersioner Versioner
cliVersioner github.Versioner
configFilePath string
}

// NewRootCommand returns a new command registered in the parent.
func NewRootCommand(parent cmd.Registerer, configFilePath string, cliVersioner Versioner, globals *config.Data) *RootCommand {
func NewRootCommand(parent cmd.Registerer, configFilePath string, cliVersioner github.Versioner, globals *config.Data) *RootCommand {
var c RootCommand
c.Globals = globals
c.CmdClause = parent.Command("update", "Update the CLI to the latest version")
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/version/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/compute"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/revision"
"github.com/fastly/cli/pkg/useragent"
"github.com/fastly/go-fastly/v7/fastly"
Expand All @@ -27,11 +27,11 @@ func init() {
// It should be installed under the primary root command.
type RootCommand struct {
cmd.Base
viceroyVersioner update.Versioner
viceroyVersioner github.Versioner
}

// NewRootCommand returns a new command registered in the parent.
func NewRootCommand(parent cmd.Registerer, viceroyVersioner update.Versioner) *RootCommand {
func NewRootCommand(parent cmd.Registerer, viceroyVersioner github.Versioner) *RootCommand {
var c RootCommand
c.viceroyVersioner = viceroyVersioner
c.CmdClause = parent.Command("version", "Display version information for the Fastly CLI")
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/fastly/cli/pkg/app"
"github.com/fastly/cli/pkg/commands/compute"
"github.com/fastly/cli/pkg/commands/update"
"github.com/fastly/cli/pkg/github"
"github.com/fastly/cli/pkg/testutil"
)

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestVersion(t *testing.T) {
args := testutil.Args("version")
opts := testutil.NewRunOpts(args, &stdout)
opts.Versioners = app.Versioners{
Viceroy: update.NewGitHub(update.GitHubOpts{
Viceroy: github.New(github.Opts{
Org: "fastly",
Repo: "viceroy",
Binary: "viceroy",
Expand Down
3 changes: 3 additions & 0 deletions pkg/github/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package github contains functions for checking the latest software
// versions hosted by GitHub.
package github
Loading