-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runs `golangci-lint --fix` and `golines`.
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package sggofumpt | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"go.einride.tech/sage/sg" | ||
"go.einride.tech/sage/sgtool" | ||
) | ||
|
||
const ( | ||
name = "gofumpt" | ||
version = "0.6.0" | ||
) | ||
|
||
// Command returns an [*exec.Cmd] for golines. | ||
func Command(ctx context.Context, args ...string) *exec.Cmd { | ||
sg.Deps(ctx, PrepareCommand) | ||
return sg.Command(ctx, sg.FromBinDir(name), args...) | ||
} | ||
|
||
func PrepareCommand(ctx context.Context) error { | ||
binDir := sg.FromToolsDir(name, version) | ||
binary := filepath.Join(binDir, name) | ||
hostOS := runtime.GOOS | ||
hostArch := runtime.GOARCH | ||
binURL := fmt.Sprintf( | ||
"https://github.com/mvdan/gofumpt/"+ | ||
"releases/download/v%s/gofumpt_v%s_%s_%s", | ||
version, | ||
version, | ||
hostOS, | ||
hostArch, | ||
) | ||
if err := sgtool.FromRemote( | ||
ctx, | ||
binURL, | ||
sgtool.WithDestinationDir(binDir), | ||
sgtool.WithRenameFile(fmt.Sprintf("gofumpt_v%s_%s_%s", version, hostOS, hostArch), name), | ||
sgtool.WithSkipIfFileExists(binary), | ||
sgtool.WithSymlink(binary), | ||
); err != nil { | ||
return fmt.Errorf("unable to download %s: %w", name, err) | ||
} | ||
if err := os.Chmod(binary, 0o755); err != nil { | ||
return fmt.Errorf("unable to make %s command: %w", name, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters