Skip to content

Commit

Permalink
Add Makefile and README
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarden committed Dec 5, 2023
1 parent af89059 commit 34a230e
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: 2
jobs:
build:
docker:
- image: cimg/go:1.21
steps:
- checkout
- run: go install github.com/mitchellh/gox@latest
- run: go install github.com/tcnksm/[email protected]
- run: sudo apt-get update && sudo apt-get install p7zip-full
- run: make dist
- run:
name: create release
command: |
if [ "$CIRCLE_TAG" ]; then
mkdir -p dist
mv apexfmt*.zip dist
ghr -t $GITHUB_TOKEN -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME --replace $CIRCLE_TAG dist/
else
echo "No tag"
fi
workflows:
version: 2
build-workflow: # the name of our workflow
jobs: # the jobs that we are sequencing.
- build:
filters:
tags:
only: /^v.*/
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
VERSION=$(shell git describe --abbrev=0 --always)
LDFLAGS = -ldflags "-X github.com/octoberswimmer/apexfmt/cmd.version=${VERSION}"
GCFLAGS = -gcflags="all=-N -l"
EXECUTABLE=apexfmt
WINDOWS=$(EXECUTABLE)_windows_amd64.exe
LINUX=$(EXECUTABLE)_linux_amd64
OSX_AMD64=$(EXECUTABLE)_osx_amd64
OSX_ARM64=$(EXECUTABLE)_osx_arm64
ALL=$(WINDOWS) $(LINUX) $(OSX_AMD64) $(OSX_ARM64)

default:
go build ${LDFLAGS}

install:
go install ${LDFLAGS}

install-debug:
go install ${LDFLAGS} ${GCFLAGS}

$(WINDOWS):
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) ${LDFLAGS}

$(LINUX):
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) ${LDFLAGS}

$(OSX_AMD64):
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -o $(OSX_AMD64) ${LDFLAGS}

$(OSX_ARM64):
env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -v -o $(OSX_ARM64) ${LDFLAGS}

$(basename $(WINDOWS)).zip: $(WINDOWS)
zip $@ $<
7za rn $@ $< $(EXECUTABLE)$(suffix $<)

%.zip: %
zip $@ $<
7za rn $@ $< $(EXECUTABLE)

docs:
go run docs/mkdocs.go

dist: test $(addsuffix .zip,$(basename $(ALL)))

fmt:
go fmt ./...

test:
test -z "$(go fmt)"
go vet
go test ./...
go test -race ./...

clean:
-rm -f $(EXECUTABLE) $(EXECUTABLE)_*

.PHONY: default dist clean docs

generate:
go generate ./...
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# apexfmt

Apexfmt formats
[Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm)
code. It uses tabs for indentation.

Given a file, it writes the formatted code to standard output by default. The
`--write`/`-w` flag can be used to overwrite the original file(s). The
`--list`/`-l` flag can be used to list files with formatting different from
apexfmt's.

# Usage

```
$ apexfmt -w sfdx/main/default/classes/*.cls sfdx/main/default/triggers/*.trigger
```

# Thanks

apexfmt is inspired by [gofmt](https://pkg.go.dev/cmd/gofmt).

The antlr4 grammar is based on the @nawforce's
[apex-parser](https://github.com/nawforce/apex-parser) grammar, which is
originally based on the grammer used by @neowit's
[tooling-force.com](https://github.com/neowit/tooling-force.com).
16 changes: 16 additions & 0 deletions docs/apexfmt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## apexfmt

Format Apex

```
apexfmt [file...]
```

### Options

```
-h, --help help for apexfmt
-l, --list list files whose formatting differs from apexfmt's
-w, --write write result to (source) file instead of stdout
```

15 changes: 15 additions & 0 deletions docs/mkdocs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
cmd "github.com/octoberswimmer/apexfmt/cmd"

"github.com/spf13/cobra/doc"
)

func main() {
cmd.RootCmd.DisableAutoGenTag = true
err := doc.GenMarkdownTree(cmd.RootCmd, "./docs")
if err != nil {
panic(err.Error())
}
}
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ module github.com/octoberswimmer/apexfmt

go 1.21.4

require github.com/antlr4-go/antlr/v4 v4.13.0
require (
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
Expand All @@ -11,4 +18,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 34a230e

Please sign in to comment.