Skip to content

Add version output #71

@nitrocode

Description

@nitrocode

It would be nice to add a version output.

The version seems to be passed in

- name: Update environment
run: |
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TARGET_NAME=hcl2json_${{ matrix.os.name }}_${{ matrix.arch}}${{ matrix.os.ext }}" >> $GITHUB_ENV
- name: Build
run: 'go build -ldflags="-X main.Version=${{ env.VERSION }}"'
- name: Upload
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mv hcl2json${{ matrix.os.ext }} $TARGET_NAME
gh release upload v$VERSION $TARGET_NAME

But not exposed as a flag

hcl2json/main.go

Lines 17 to 20 in 75e097e

var options convert.Options
flag.BoolVar(&options.Simplify, "simplify", false, "If true attempt to simply expressions which don't contain any variables or unknown functions")
flag.Parse()


It could be as simple as this

import (
	"bytes"
	"encoding/json"
	"flag"
+	"fmt"
	"io"
	"log"
	"os"

	"github.com/tmccombs/hcl2json/convert"
)

+var (
+    version = "dev"
+)

func main() {
	logger := log.New(os.Stderr, "", 0)

	var options convert.Options

	flag.BoolVar(&options.Simplify, "simplify", false, "If true attempt to simply expressions which don't contain any variables or unknown functions")
+	flag.BoolVar(&options.Version, "version", false, "return version")
	flag.Parse()

+	if options.Version {
+		fmt.Println(options.Version)
+		os.Exit(0)
+	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions