Skip to content

Commit 677ace5

Browse files
feat: initialize cli (#1)
1 parent 85751e4 commit 677ace5

File tree

13 files changed

+311
-0
lines changed

13 files changed

+311
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
3+
{
4+
"name": "Go 1.23",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/go:1-1.23-bullseye",
7+
8+
"mounts": [
9+
"type=bind,source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,readonly"
10+
],
11+
12+
"settings": {
13+
"workbench.colorCustomizations": {
14+
"statusBar.background": "#ff4088",
15+
"statusBar.foreground": "#ffffff"
16+
}
17+
},
18+
"features": {
19+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
20+
}
21+
22+
}

.github/workflows/main.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Go Test
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
go-version: [ '1.23' ]
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: ${{ matrix.go-version }}
18+
- name: Install dependencies
19+
run: go get .
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v6
22+
with:
23+
version: v1.62.2
24+
- name: Run unit-tests
25+
run: go test -v ./...
26+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
name: release-please
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: googleapis/release-please-action@v4
17+
with:
18+
token: ${{ secrets.RELEASE_TOKEN }}
19+
release-type: go

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
GO_VERSION: "1.23"
13+
14+
jobs:
15+
manual-release:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout sources
19+
uses: actions/checkout@v4
20+
21+
- name: Install go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: ${{ env.GO_VERSION }}
25+
26+
- name: Perform cross builds
27+
run: make cross
28+
29+
- name: Compress binaries
30+
run: |
31+
cd out
32+
tar czf web3datacli_${GITHUB_REF#refs/tags/}_darwin_amd64.tar.gz web3datacli_${GITHUB_REF#refs/tags/}_darwin_amd64/
33+
tar czf web3datacli_${GITHUB_REF#refs/tags/}_linux_amd64.tar.gz web3datacli_${GITHUB_REF#refs/tags/}_linux_amd64/
34+
35+
- name: Get git tag
36+
run: echo "tag=$(git describe --tags --exact-match HEAD)" >> $GITHUB_ENV
37+
38+
- name: Publish binaries
39+
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # 2.9.0
40+
with:
41+
repo_token: ${{ secrets.RELEASE_TOKEN }}
42+
tag: ${{ env.tag }}
43+
release_name: ${{ env.tag }}
44+
file_glob: true
45+
file: out/*.tar.gz
46+
overwrite: true

.golangci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
linters-settings:
2+
errcheck:
3+
check-type-assertions: true
4+
exhaustive:
5+
default-signifies-exhaustive: true
6+
goconst:
7+
min-len: 2
8+
min-occurrences: 3
9+
gocritic:
10+
enabled-tags:
11+
- diagnostic
12+
- experimental
13+
- opinionated
14+
- performance
15+
- style
16+
govet:
17+
enable-all: true
18+
stylecheck:
19+
checks: ["ST1000", "ST1001"]
20+
nolintlint:
21+
require-explanation: true
22+
require-specific: true
23+
wsl:
24+
allow-assign-and-anything: true
25+
allow-cuddle-declarations: true
26+
allow-assign-and-call: true
27+
28+
linters:
29+
disable-all: true
30+
enable:
31+
- bodyclose
32+
- dogsled
33+
- dupl
34+
- errcheck
35+
- copyloopvar
36+
- exhaustive
37+
- goconst
38+
- gofmt
39+
- goimports
40+
- govet
41+
- mnd
42+
- gocyclo
43+
- gosec
44+
- gosimple
45+
- govet
46+
- ineffassign
47+
- misspell
48+
- nolintlint
49+
- nakedret
50+
- prealloc
51+
- predeclared
52+
- staticcheck
53+
- stylecheck
54+
- thelper
55+
- tparallel
56+
- typecheck
57+
- unconvert
58+
- unparam
59+
- whitespace
60+
- wsl
61+
62+
run:
63+
issues-exit-code: 1

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ ".": "1.0.0" }

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.DEFAULT_GOAL := help
2+
3+
BIN_NAME := web3datacli
4+
BUILD_DIR := ./out
5+
6+
GIT_SHA := $(shell git rev-parse HEAD | cut -c 1-8)
7+
GIT_TAG := $(shell git describe --tags)
8+
DATE := $(shell date +%s)
9+
VERSION_FLAGS=\
10+
-X github.com/thewhitewizard/web3data-cli/cmd/version.Version=$(GIT_TAG) \
11+
-X github.com/thewhitewizard/web3data-cli/cmd/version.Commit=$(GIT_SHA) \
12+
-X github.com/thewhitewizard/web3data-cli/cmd/version.Date=$(DATE) \
13+
-X github.com/thewhitewizard/web3data-cli/cmd/version.BuiltBy=makefile
14+
15+
.PHONY: help
16+
help: ## Display this help.
17+
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
18+
19+
##@ Build
20+
21+
.PHONY: $(BUILD_DIR)
22+
$(BUILD_DIR): ## Create the build folder.
23+
mkdir -p $(BUILD_DIR)
24+
25+
.PHONY: build
26+
build: $(BUILD_DIR) ## Build go binary.
27+
go build -ldflags "$(VERSION_FLAGS)" -o $(BUILD_DIR)/$(BIN_NAME) main.go
28+
29+
.PHONY: cross
30+
cross: $(BUILD_DIR) ## Cross-compile go binaries without using CGO.
31+
GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(BIN_NAME)_$(GIT_TAG)_linux_amd64 main.go
32+
GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/$(BIN_NAME)_$(GIT_TAG)_darwin_amd64 main.go
33+
34+
.PHONY: clean
35+
clean: ## Clean the binary folder.
36+
$(RM) -r $(BUILD_DIR)

cmd/root.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"github.com/thewhitewizard/web3data-cli/cmd/version"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var rootCmd = &cobra.Command{
10+
Use: "web3datacli",
11+
Long: `A CLI tool to manage web3data`,
12+
}
13+
14+
func Execute() {
15+
cobra.CheckErr(rootCmd.Execute())
16+
}
17+
18+
func init() {
19+
rootCmd.AddCommand(version.VersionCmd)
20+
}

cmd/version/version.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package version
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var (
8+
Version = "dev"
9+
Commit = "none"
10+
Date = "unknown"
11+
BuiltBy = "unknown"
12+
)
13+
14+
var VersionCmd = &cobra.Command{
15+
Use: "version",
16+
Short: "Get the current version of this application",
17+
Long: `Nothing fancy. Print the version of this application`,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
cmd.Printf("web3datacli Version %s\n", Version)
20+
},
21+
}

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/thewhitewizard/web3data-cli
2+
3+
go 1.23.4
4+
5+
require github.com/spf13/cobra v1.9.1
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.6 // indirect
10+
)

0 commit comments

Comments
 (0)