-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from metal3d/develop
Strong rewrite, add diff output, changed logger...
- Loading branch information
Showing
10 changed files
with
395 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,20 +25,22 @@ jobs: | |
coverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
if: success() | ||
uses: actions/setup-go@v3 | ||
- uses: actions/checkout@v3 | ||
with: | ||
go-version: 1.18 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Calc coverage | ||
run: | | ||
go test -v -covermode=count -coverprofile=coverage.out ./... | ||
- name: gcov2lcov-action | ||
uses: jandelgado/[email protected] | ||
- name: Coveralls | ||
uses: coverallsapp/github-action@master | ||
# default fetch-depth is insufficent to find previous coverage notes | ||
fetch-depth: 10 | ||
|
||
- uses: gwatts/go-coverage-action@v1 | ||
id: coverage | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: coverage.lcov | ||
# Optional coverage threshold | ||
# use fail-coverage to determine what should happen below this threshold | ||
coverage-threshold: 80 | ||
|
||
# collect coverage for all packages beyond the one under test | ||
cover-pkg: ./... | ||
|
||
# Ignore code-generated files when calculating coverage totals | ||
ignore-pattern: | | ||
\.pb\.go$ | ||
\_string\.go$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
go.sum | ||
examples/* | ||
./goreorder | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ DIST_CC:=podman run | |
DIST_CC_OPTS:=--rm -i --userns keep-id -v $(PWD):/go/src/github.com/metal3d/goreorder:z -w /go/src/github.com/metal3d/goreorder -e CGO_ENABLED=0 docker.io/golang:1.18 | ||
CC=go | ||
CC_OPTS=-ldflags "-X main.version=$(VERSION)" | ||
SIGNER[email protected] | ||
|
||
TARGETS=dist/goreorder-linux-amd64 dist/goreorder-darwin-amd64 dist/goreorder-windows-amd64.exe dist/goreorder-freebsd-amd64 | ||
|
||
install: | ||
go install -v $(CC_OPTS) $(PACKAGE) | ||
|
@@ -23,25 +26,22 @@ dev-build: | |
go build -v $(CC_OPTS) -o goreorder ./cmd/goreorder/*.go | ||
|
||
.ONESHELL: | ||
dist: clean-dist | ||
mkdir -p dist | ||
$(MAKE) dist/goreorder-linux-amd64 | ||
$(MAKE) dist/goreorder-darwin-amd64 | ||
$(MAKE) dist/goreorder-windows-amd64.exe | ||
$(MAKE) dist/goreorder-freebsd-amd64 | ||
dist: clean-dist $(TARGETS) | ||
# stripping | ||
strip dist/goreorder-linux-amd64 || true | ||
strip dist/goreorder-darwin-amd64 || true | ||
strip dist/goreorder-windows-amd64.exe || true | ||
strip dist/goreorder-freebsd-amd64 || true | ||
# sign | ||
|
||
|
||
gpg-sign: | ||
# sign with gpg | ||
for i in $$(find dist -type f); do | ||
echo "signing $$i" | ||
echo "sha256: $$(sha256sum $$i)" >> $$i.sha256 | ||
echo "Signing $$i with gpg..." | ||
gpg --armor --detach-sign --local-user $(SIGNER) $$i | ||
done | ||
|
||
|
||
|
||
dist/goreorder-linux-amd64: | ||
@mkdir -p dist | ||
ifeq ($(strip $(_CNT)),true) | ||
|
@@ -80,6 +80,5 @@ clean-dist: | |
clean: clean-dist | ||
rm -f ./goreorder | ||
|
||
|
||
test: | ||
go test ./ordering -v -cover | ||
test: | ||
go test -v -race -cover -short ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,80 @@ | ||
[](https://coveralls.io/github/metal3d/goreorder?branch=main) | ||
|
||
# EXPERIMENTAL go source reoreding | ||
|
||
This tool is EXPERIMENTAL! We strongly recommend to backup (or use git to commit your changes) before to try it. | ||
|
||
This tool will "reorder" your sources to do this: | ||
|
||
- alphabetic reorder you methods and constructors (constructors will be also placed above methods) | ||
- place methods and constructors above the `type` definition | ||
- rewrite (or output) the result | ||
- place methods and constructors below the `type` definition | ||
- output the result or write or even generate a patch file | ||
|
||
Usage: | ||
# Install | ||
|
||
``` | ||
Usage of goreorder: | ||
-dir string | ||
directory to scan (default ".") | ||
-file string | ||
file to process, deactivates -dir if set | ||
-format string | ||
the executable to use to format the output (default "gofmt") | ||
-output string | ||
output file (default to the original file, only works with -file) | ||
-reorder-structs | ||
reorder structs by name (default: false) | ||
-verbose | ||
get some informations while processing | ||
-version | ||
show version (master) | ||
-write | ||
write the output to the file, if not set it will print to stdout (default: false) | ||
``` | ||
Get release or use `go install github.com/metal3d/goreorder@latest` and download corresponding binary inside your `$PATH`. | ||
|
||
By default, the tool will scan everything in the current directory and output result to standard output (no write). | ||
You can use this script to install `goreorder` as user or with `sudo`, the script will detect if you are simple user | ||
and will try to install in `$HOME/.local/bin` then `$HOME/bin` it the first one doesn't exists. | ||
|
||
# Install | ||
```bash | ||
curl -sSL https://raw.githubusercontent.com/metal3d/goreorder/main/repo-tools/install.sh | bash -s | ||
``` | ||
|
||
Get release or use `go install github.com/metal3d/goreorder@latest` and download corresponding binary inside your `$PATH`. You can use this script to install `goreorder` as user or with `sudo`, the script will detect if you are simple user and will try to install in `$HOME/.local/bin` then `$HOME/bin` it the first one doesn't exists. | ||
You can also get this repository and build it with the `Makefile`: | ||
|
||
```bash | ||
curl -sSL https://raw.githubusercontent.com/metal3d/goreorder/main/repo-tools/install.sh | bash | ||
git clone [email protected]:metal3d/goreorder.git | ||
cd goreorder | ||
make install | ||
``` | ||
|
||
If you want to install from source: | ||
## Basic Usage | ||
|
||
```bash | ||
go install -v github.com/metal3d/goreorder/cmd/... | ||
``` | ||
goreorder reorders the structs (optional), methods and constructors in a Go | ||
source file. By default, it will print the result to stdout. To allow goreorder | ||
to write to the file, use the -write flag. | ||
You can also get this repository and type: | ||
Usage: | ||
goreorder [flags] [file.go|directory|stdin] | ||
goreorder [command] | ||
Examples: | ||
$ goreorder reorder --write --reorder-structs --format gofmt file.go | ||
$ goreorder reorder --diff ./mypackage | ||
$ cat file.go | goreorder reorder | ||
Available Commands: | ||
completion Generates completion scripts | ||
help Help about any command | ||
reorder Reorder stucts, methods and constructors in a Go source file. | ||
Flags: | ||
-h, --help Show help | ||
-V, --version Show version | ||
Use "goreorder [command] --help" for more information about a command. | ||
``` | ||
|
||
# Avoid destruction with `--diff` | ||
|
||
If your system provides `diff` and `patch` command, it is safier to use the `--diff` option to geneate | ||
a `patch` file. This file can then be used to apply changes, and to revert your changes if it fails. | ||
|
||
Example: | ||
```bash | ||
git clone [email protected]:metal3d/goreorder.git | ||
cd goreorder | ||
make install | ||
goreorder reorder --diff ./ > reorder.patch | ||
|
||
# try to apply | ||
patch -p1 --dry-run < ./reorder.patch | ||
# really apply | ||
patch -p1 < ./reorder.patch | ||
|
||
# revert the changes | ||
patch -p1 -R < ./reorder.patch | ||
``` | ||
|
||
# Contribute | ||
|
||
Please fill an issue to create a bug report. | ||
|
||
If you want to participate, please fork the repository and propose a pull request. | ||
If you want to participate, please fork the repository and propose a pull request **on the "develop" branch**. |
Oops, something went wrong.