Skip to content

Commit

Permalink
refactor the code to allow it to be easily go installable
Browse files Browse the repository at this point in the history
  • Loading branch information
BradLewis committed May 25, 2024
1 parent afb8db1 commit c8d33b5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ gosec: ## Runs gosec on the codebase

format-go: ## Runs go-fmt on the codebase
@printf "%s\n" "==== Running go-fmt ====="
gofmt -s -w *.go cmd/*.go
gofmt -s -w .

golines-format: ## Runs golines on the codebase
# https://github.com/segmentio/golines
Expand All @@ -86,51 +86,51 @@ go-staticcheck: ## Runs staticcheck on the codebase
staticcheck ./...

run: ## Runs the binary
go run cmd/*.go $(ARGS)
go run main.go $(ARGS)

test: ## Runs the tests
go test -v .

build: format-lint ## Builds the binary for your current platform
go build -o bin/${BINARY_NAME} cmd/*.go
go build -o bin/${BINARY_NAME} main.go

build-prod: format-lint ## Builds the binary for your current platform with production flags
go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME} cmd/*.go
go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME} main.go

build-darwin: format-lint ## Builds the binary for darwin
@printf "%s\n" "==== Building for Darwin ====="
env GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}_darwin_arm64 cmd/*.go
env GOOS=darwin GOARCH=amd64 go build -o bin/${BINARY_NAME}_darwin_amd64 cmd/*.go
env GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}_darwin_arm64 main.go
env GOOS=darwin GOARCH=amd64 go build -o bin/${BINARY_NAME}_darwin_amd64 main.go
lipo -create -output bin/${BINARY_NAME}_darwin bin/${BINARY_NAME}_darwin_arm64 bin/${BINARY_NAME}_darwin_amd64

build-darwin-prod: ## Builds the binary for darwin with production flags
@printf "%s\n" "==== Building for Darwin (Production) ====="
env GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_darwin_arm64 cmd/*.go
env GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_darwin_amd64 cmd/*.go
env GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_darwin_arm64 main.go
env GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_darwin_amd64 main.go

build-linux-arm64: format-lint ## Builds the binary for linux arm64
@printf "%s\n" "==== Building for linux arm64 ====="
env GOOS=linux GOARCH=arm64 go build -o bin/${BINARY_NAME}_linux_arm64 cmd/*.go
env GOOS=linux GOARCH=arm64 go build -o bin/${BINARY_NAME}_linux_arm64 main.go

build-linux-arm64-prod: ## Builds the binary for linux arm64 with production flags
@printf "%s\n" "==== Building for linux arm64 (Production) ====="
env GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_linux_arm64 cmd/*.go
env GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_linux_arm64 main.go

build-linux-amd64: format-lint ## Builds the binary for linux amd64
@printf "%s\n" "==== Building for linux amd64 ====="
env GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}_linux_amd64 cmd/*.go
env GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}_linux_amd64 main.go

build-linux-amd64-prod: ## Builds the binary for linux amd64 with production flags
@printf "%s\n" "==== Building for linux amd64 (Production) ====="
env GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_linux_amd64 cmd/*.go
env GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_linux_amd64 main.go

build-windows-amd64: format-lint ## Builds the binary for windows amd64
@printf "%s\n" "==== Building for windows amd64 ====="
env GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}_windows_amd64 cmd/*.go
env GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}_windows_amd64 main.go

build-windows-amd64-prod: ## Builds the binary for windows amd64 with production flags
@printf "%s\n" "==== Building for windows amd64 (Production) ====="
env GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_windows_amd64 cmd/*.go
env GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/${BINARY_NAME}_windows_amd64 main.go

build-all: build-darwin build-linux-arm64 build-linux-amd64 build-windows-amd64 ## Builds the binary for all platforms

Expand Down
7 changes: 0 additions & 7 deletions cmd/main.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/anchor/root.go → cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package anchor
package cmd

import (
"bufio"
Expand All @@ -15,7 +15,7 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/spf13/cobra"

"github.com/songstitch/anchor"
"github.com/songstitch/anchor/pkg/anchor"
)

type Options struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/anchor/version.go → cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package anchor
package cmd

import (
"fmt"
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/songstitch/anchor/cmd"

func main() {
cmd.Execute()
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c8d33b5

Please sign in to comment.