Skip to content

Commit

Permalink
Add CLI Commands and Makefile (#7)
Browse files Browse the repository at this point in the history
* Install commands for building

* remove main.go

* update icon
  • Loading branch information
keefertaylor authored Oct 30, 2023
1 parent bf20092 commit b5bce1b
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 138 deletions.
72 changes: 25 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,51 @@

DOCKER := $(shell which docker)

CURRENT_DIR = $(shell pwd)
BUILDDIR ?= $(CURDIR)/build

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')

# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
DIRTY := -dirty
ifeq (,$(shell git status --porcelain))
DIRTY :=
endif

###############################################################################
### Protobuf ###
###############################################################################

protoImageName=proto-genc
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace/proto $(protoImageName)

proto-all: proto-build-docker proto-format proto-lint make proto-format proto-update-deps proto-gen

proto-build-docker:
@echo "Building Docker Container '$(protoImageName)' for Protobuf Compilation"
@docker build -t $(protoImageName) -f ./proto/Dockerfile .

proto-gen:
@echo "Generating Protobuf Files"
@$(protoImage) sh -c "cd .. && sh ./scripts/protocgen.sh"
VERSION := $(shell git describe --tags --exact-match 2>/dev/null)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif

proto-format:
@echo "Formatting Protobuf Files with Clang"
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
VERSION := $(VERSION)$(DIRTY)

proto-lint:
@echo "Linting Protobuf Files With Buf"
@$(protoImage) buf lint
GIT_REVISION := $(shell git rev-parse HEAD)$(DIRTY)

proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)

proto-update-deps:
@echo "Updating Protobuf dependencies"
@$(protoImage) buf mod update
ldflags= -X github.com/tessellated-io/paymaster/cmd/paymaster/cmd.PaymasterVersion=${VERSION} \
-X github.com/tessellated-io/paymaster/cmd/paymaster/cmd.GitRevision=${GIT_REVISION} \
-X github.com/tessellated-io/paymaster/cmd/paymaster/cmd.GoVersion=${GO_SYSTEM_VERSION}

.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking proto-update-deps
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

###############################################################################
### Build ###
###############################################################################

BUILD_TARGETS := build

build: BUILD_ARGS=

build-linux-amd64:
@GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build
build:
mkdir -p $(BUILDDIR)/
go build -mod=readonly -ldflags '$(ldflags)' -trimpath -o $(BUILDDIR) ./...;

build-linux-arm64:
@GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build
install: go.sum
go install $(BUILD_FLAGS) ./cmd/paymaster

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
@cd ${CURRENT_DIR} && go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
clean:
rm -rf $(BUILDDIR)/*

$(BUILDDIR)/:
@mkdir -p $(BUILDDIR)/
.PHONY: build

###############################################################################
### Tools & Dependencies ###
Expand Down
4 changes: 2 additions & 2 deletions bursar/bursar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

"github.com/tessellated-io/mail-in-rebates/paymaster/crypto"
"github.com/tessellated-io/mail-in-rebates/paymaster/skip"
"github.com/tessellated-io/paymaster/crypto"
"github.com/tessellated-io/paymaster/skip"
"github.com/tessellated-io/pickaxe/arrays"
"github.com/tessellated-io/pickaxe/chains"
"github.com/tessellated-io/pickaxe/coding"
Expand Down
10 changes: 5 additions & 5 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package cmd

import (
"github.com/spf13/cobra"
"github.com/tessellated-io/mail-in-rebates/paymaster/bursar"
"github.com/tessellated-io/mail-in-rebates/paymaster/codec"
"github.com/tessellated-io/mail-in-rebates/paymaster/server"
"github.com/tessellated-io/mail-in-rebates/paymaster/skip"
"github.com/tessellated-io/mail-in-rebates/paymaster/tracker"
"github.com/tessellated-io/paymaster/bursar"
"github.com/tessellated-io/paymaster/codec"
"github.com/tessellated-io/paymaster/server"
"github.com/tessellated-io/paymaster/skip"
"github.com/tessellated-io/paymaster/tracker"
"github.com/tessellated-io/pickaxe/chains"
pacrypto "github.com/tessellated-io/pickaxe/crypto"
)
Expand Down
29 changes: 29 additions & 0 deletions cmd/paymaster/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright © 2023 Tessellated <tessellated.io>
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "paymaster",
Short: "Paymaster automatically tops of balances of addresses on the interchain.",
// TODO: Consider long form here
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
}
22 changes: 22 additions & 0 deletions cmd/paymaster/cmd/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright © 2023 Tessellated <tessellated.io>
*/
package cmd

import (
"github.com/spf13/cobra"
)

// startCmd represents the start command
var startCmd = &cobra.Command{
Use: "start",
Short: "Start paymaster",
Long: `Starts paymaster with the given configuration.`,
Run: func(cmd *cobra.Command, args []string) {
panic("TODO: Implement me")
},
}

func init() {
rootCmd.AddCommand(startCmd)
}
39 changes: 39 additions & 0 deletions cmd/paymaster/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright © 2023 Tessellated <tessellated.io>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// Binary name
const (
binaryName = "paymaster"
binaryIcon = "💸"
)

// Version
var (
PaymasterVersion string
GoVersion string
GitRevision string
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the current version of paymaster",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s %s:\n", binaryIcon, binaryName)
fmt.Printf(" - Version: %s\n", PaymasterVersion)
fmt.Printf(" - Git Revision: %s\n", GitRevision)
fmt.Printf(" - Go Version: %s\n", GoVersion)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
10 changes: 10 additions & 0 deletions cmd/paymaster/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright © 2023 Tessellated <tessellated.io>
*/
package main

import "github.com/tessellated-io/paymaster/cmd/paymaster/cmd"

func main() {
cmd.Execute()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/tessellated-io/mail-in-rebates/paymaster
module github.com/tessellated-io/paymaster

go 1.20

Expand Down
78 changes: 0 additions & 78 deletions main.go

This file was deleted.

6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"sync"
"time"

"github.com/tessellated-io/mail-in-rebates/paymaster/bursar"
proto "github.com/tessellated-io/mail-in-rebates/paymaster/server/proto"
"github.com/tessellated-io/mail-in-rebates/paymaster/tracker"
"github.com/tessellated-io/paymaster/bursar"
proto "github.com/tessellated-io/paymaster/server/proto"
"github.com/tessellated-io/paymaster/tracker"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
)
Expand Down
2 changes: 1 addition & 1 deletion skip/api-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

ibctypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/tessellated-io/mail-in-rebates/paymaster/crypto"
"github.com/tessellated-io/paymaster/crypto"
"github.com/tessellated-io/pickaxe/chains"

cdc "github.com/cosmos/cosmos-sdk/codec"
Expand Down
2 changes: 1 addition & 1 deletion tracker/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tracker_test
import (
"testing"

"github.com/tessellated-io/mail-in-rebates/paymaster/tracker"
"github.com/tessellated-io/paymaster/tracker"
)

func TestFileWrite(t *testing.T) {
Expand Down

0 comments on commit b5bce1b

Please sign in to comment.