Skip to content

Commit

Permalink
feat(sggh): add support for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kutkaite committed Oct 2, 2024
1 parent 35ddb9b commit 6b95456
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tools/sggh/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,37 @@ func Command(ctx context.Context, args ...string) *exec.Cmd {

func PrepareCommand(ctx context.Context) error {
hostOS := runtime.GOOS
ext := "tar.gz"
if hostOS == sgtool.Darwin {
hostOS = "macOS"
ext = "zip"
}
hostArch := runtime.GOARCH
binDir := sg.FromToolsDir(name, version)
binary := filepath.Join(binDir, name)
binURL := fmt.Sprintf(
"https://github.com/cli/cli/releases/download/v%s/gh_%s_%s_%s.tar.gz",
"https://github.com/cli/cli/releases/download/v%s/gh_%s_%s_%s.%s",
version,
version,
hostOS,
hostArch,
ext,
)
if err := sgtool.FromRemote(
ctx,
binURL,
opts := []sgtool.Opt{
sgtool.WithDestinationDir(binDir),
sgtool.WithUntarGz(),
sgtool.WithRenameFile(fmt.Sprintf("gh_%s_%s_%s/bin/gh", version, hostOS, hostArch), name),
sgtool.WithSkipIfFileExists(binary),
sgtool.WithSymlink(binary),
}
if hostOS == "macOS" {
opts = append(opts, sgtool.WithUnzip())
} else {
opts = append(opts, sgtool.WithUntarGz())
}
if err := sgtool.FromRemote(
ctx,
binURL,
opts...,
); err != nil {
return fmt.Errorf("unable to download %s: %w", name, err)
}
Expand Down

0 comments on commit 6b95456

Please sign in to comment.