Skip to content

Commit

Permalink
version and updated README.md with the required details. (#20)
Browse files Browse the repository at this point in the history
1. Added support to check for version as well -help falg to print usage.
2. Created README.md with minimum required details possible.
  • Loading branch information
pandurangpatil authored Jun 15, 2023
1 parent def385a commit 731a9c1
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
echo "The current tag is: ${{ steps.taggerDryRun.outputs.tag }}"
- name: Build
run: |
GOOS=linux GOARCH=amd64 go build -o build/goastgen-linux
GOOS=linux GOARCH=arm64 go build -o build/goastgen-linux-arm64
GOOS=windows GOARCH=amd64 go build -o build/goastgen-windows.exe
GOOS=darwin GOARCH=amd64 go build -o build/goastgen-macos
GOOS=darwin GOARCH=arm64 go build -o build/goastgen-macos-arm64
GOOS=linux GOARCH=amd64 go build -o build/goastgen-linux -ldflags "-X main.Version=${{ steps.taggerDryRun.outputs.tag }}"
GOOS=linux GOARCH=arm64 go build -o build/goastgen-linux-arm64 -ldflags "-X main.Version=${{ steps.taggerDryRun.outputs.tag }}"
GOOS=windows GOARCH=amd64 go build -o build/goastgen-windows.exe -ldflags "-X main.Version=${{ steps.taggerDryRun.outputs.tag }}"
GOOS=darwin GOARCH=amd64 go build -o build/goastgen-macos -ldflags "-X main.Version=${{ steps.taggerDryRun.outputs.tag }}"
GOOS=darwin GOARCH=arm64 go build -o build/goastgen-macos-arm64 -ldflags "-X main.Version=${{ steps.taggerDryRun.outputs.tag }}"
- name: Set next release version
id: taggerFinal
uses: anothrNick/[email protected]
Expand Down
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# AST generator

This utility generates Abstract Syntax Tree (AST) for .go files in JSON format.

If you pass the root folder of the go project, it will iterate through all `.go` files from project directory
and generate ast in JSON format for each `.go` file.

## Usage

## Building

Run below command from within root folder of the cloned repository.

```bash
go build -o build/goastgen
```

This will generate native binary for your local machine inside `build` folder

## Getting Help

```bash
build/goastgen -help

Usage:
goastgen [falgs] <source location>

Flags:
-help
print the usage
-out string
Out put location of ast (default ".ast")
-version
print the version
```

## Example

### Single file
1. Generate AST with single `.go` file path without passing `-out` flag to indicate ast json out location.

```bash
$ goastgen <filepath>/<go filename>

e.g
$ goastgen /path/src/hello.go

It should generate the AST in JSON format at

/path/src/.ast/hello.go.json
```

2. Generate AST with single `.go` file with `-out` flag

```bash
$ goastgen -out <output location> <filepath>/<go filename>

e.g
$ goastgen -out /tmp/randompath /path/src/hello.go

It should generate the AST in JSON format at

/tmp/randompath/hello.go.json
```

### Complete project directory

```bash
/path/repository
- hello.go
- anotherfile.go
- somepkg
- somelib.go
```
1. Generate AST with above root directory of the go project without passing `-out` flag
```bash
$ goastgen <root directory location of go project>

e.g.
$ goastgen /path/repository

It should generate AST in JSON fromat for each .go file at following location

/path/repository/.ast
- hello.go.json
- anotherfile.go.json
- somepkg
- somelib.go.json
```

2. Generate AST with above root directory of the go project with `-out` flag

```bash
$ goastgen -out <output location> <root directory location of go project>

e.g.
$ goastgen -out /temp/out/ /path/repository

It should generate AST in JSON fromat for each .go file at following location

/temp/out/
- hello.go.json
- anotherfile.go.json
- somepkg
- somelib.go.json
```
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
)

var Version = "dev"

func main() {
out, inputPath := parseArguments()
processRequest(out, inputPath)
Expand Down Expand Up @@ -58,15 +60,23 @@ func parseArguments() (string, string) {
var (
out string
inputPath string = ""
version bool
help bool
)
flag.StringVar(&out, "out", ".ast", "Out put location of ast")
flag.BoolVar(&version, "version", false, "print the version")
flag.BoolVar(&help, "help", false, "print the usage")
flag.Parse()
if version {
fmt.Println(Version)
os.Exit(0)
}
// Check if positional arguments exist
if flag.NArg() > 0 {
// Retrieve positional arguments
inputPath = flag.Arg(0)
}
if inputPath == "" {
if inputPath == "" || help {
fmt.Println("Usage:")
fmt.Println("\tgoastgen [falgs] <source location>")
fmt.Println()
Expand Down

0 comments on commit 731a9c1

Please sign in to comment.