Skip to content

Commit

Permalink
feat: add makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Sep 4, 2022
0 parents commit 7394963
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Go Patch ###
/vendor/
/Godeps/

# End of https://www.toptal.com/developers/gitignore/api/go

dist
safebox
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# TODO: remove hard coded version
VERSION := 1
ifndef VERSION
VERSION := $(shell git describe --tags --always --dirty="-dev")
endif

ifndef TARGETARCH
TARGETARCH := $(shell arch)
endif

LDFLAGS := -ldflags='-X "main.Version=$(VERSION)"'

test:
go test -v ./...

all: darwin-amd64 darwin-arm64 linux-amd64 windows-amd64.exe

clean: |
rm -rf ./dist
rm -f ./safebox

dist/:
mkdir -p dist

build: safebox

safebox:
CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@

linux: linux-$(TARGETARCH)
cp $^ safebox

darwin-amd64: | dist/
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o dist/safebox-$(VERSION)-$@

darwin-arm64: | dist/
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o dist/safebox-$(VERSION)-$@

linux-amd64: | dist/
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o dist/safebox-$(VERSION)-$@

linux-arm64 linux-aarch64: | dist/
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o dist/safebox-$(VERSION)-$@

windows-amd64.exe: | dist/
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o dist/safebox-$(VERSION)-$@

.PHONY: clean all linux
26 changes: 26 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"os"
"strings"

"github.com/spf13/cobra"
)

var RootCmd = &cobra.Command{
Use: "SafeBox",
Short: "SafeBox is a secret manager CLI program",
Long: `A Fast and Flexible secret manager built with love by adikari in Go.`,
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
},
}

func Execute() {
if cmd, err := RootCmd.ExecuteC(); err != nil {
if strings.Contains(err.Error(), "arg(s)") || strings.Contains(err.Error(), "usage") {
cmd.Usage()
}
os.Exit(1)
}
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/adikari/safebox/v2

go 1.19

require github.com/spf13/cobra v1.5.0

require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
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/adikari/safebox/v2/cmd"

func main() {
cmd.Execute()
}

0 comments on commit 7394963

Please sign in to comment.