Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool build #45

Merged
merged 6 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
version
  • Loading branch information
trobro committed Jul 23, 2022
commit 9a9f61f9c2575b50886775389000ac1f638920c7
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Options:
Omit braces at the root.
-quoteAlways
Always quote string values.
-v
Show version.
```

Sample:
Expand Down
5 changes: 3 additions & 2 deletions build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ function build() {
export GOARCH=$2

echo build $GOOS $GOARCH
OUT=$BINARIES/hjson_`cd $ROOT && git describe --tags`_${GOOS}_${GOARCH}
VERSION=`cd $ROOT && git describe --tags`
OUT=${BINARIES}/hjson_${VERSION}_${GOOS}_${GOARCH}
mkdir $OUT
cd $OUT
go build github.com/hjson/hjson-go/v4/hjson-cli
go build -ldflags "-w -s -X main.Version=${VERSION}" github.com/hjson/hjson-go/v4/hjson-cli
if [[ $3 == "zip" ]]; then
mv $OUT/hjson-cli.exe $OUT/hjson.exe
zip -j ${OUT}.zip $OUT/*
Expand Down
12 changes: 10 additions & 2 deletions hjson-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/hjson/hjson-go/v4"
)

// Can be set when building for example like this:
// go build -ldflags "-X main.Version=v3.0"
var Version string

func fixJSON(data []byte) []byte {
data = bytes.Replace(data, []byte("\\u003c"), []byte("<"), -1)
data = bytes.Replace(data, []byte("\\u003e"), []byte(">"), -1)
Expand Down Expand Up @@ -40,15 +44,19 @@ func main() {
var bracesSameLine = flag.Bool("bracesSameLine", false, "Print braces on the same line.")
var omitRootBraces = flag.Bool("omitRootBraces", false, "Omit braces at the root.")
var quoteAlways = flag.Bool("quoteAlways", false, "Always quote string values.")

// var showVersion = flag.Bool("V", false, "Show version.")
var showVersion = flag.Bool("v", false, "Show version.")

flag.Parse()
if *help || flag.NArg() > 1 {
flag.Usage()
os.Exit(1)
}

if *showVersion {
fmt.Println(Version)
os.Exit(0)
}

var err error
var data []byte
if flag.NArg() == 1 {
Expand Down