diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b71c045..630658d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,7 +64,7 @@ jobs: GOOS: ${{ env.OS }} GOARCH: ${{ matrix.arch }} run: | - go build -o fabric-${OS}-${{ matrix.arch }} . + go build -ldflags "-X main.version=$(git describe --tags --always)" -o fabric-${OS}-${{ matrix.arch }} . - name: Build binary on Windows if: matrix.os == 'windows-latest' @@ -72,7 +72,7 @@ jobs: GOOS: windows GOARCH: ${{ matrix.arch }} run: | - go build -o fabric-windows-${{ matrix.arch }}.exe . + go build -ldflags "-X main.version=$(git describe --tags --always)" -o fabric-windows-${{ matrix.arch }}.exe . - name: Upload build artifact if: matrix.os != 'windows-latest' diff --git a/README.md b/README.md index 8ca804e..e552ba8 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ To install Fabric, [make sure Go is installed](https://go.dev/doc/install), and ```bash # Install Fabric directly from the repo -go install github.com/danielmiessler/fabric@latest +go install -ldflags "-X main.version=$(git describe --tags --always)" github.com/danielmiessler/fabric@latest ``` ### Environment Variables diff --git a/cli/cli.go b/cli/cli.go index 45eca36..a031fe2 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -12,7 +12,7 @@ import ( ) // Cli Controls the cli. It takes in the flags and runs the appropriate functions -func Cli() (message string, err error) { +func Cli(version string) (message string, err error) { var currentFlags *Flags if currentFlags, err = Init(); err != nil { // we need to reset error, because we don't want to show double help messages @@ -20,6 +20,11 @@ func Cli() (message string, err error) { return } + if currentFlags.Version { + fmt.Println(version) + return + } + var homedir string if homedir, err = os.UserHomeDir(); err != nil { return diff --git a/cli/flags.go b/cli/flags.go index 3e5986f..27854f8 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -45,6 +45,7 @@ type Flags struct { ScrapeURL string `short:"u" long:"scrape_url" description:"Scrape website URL to markdown using Jina AI"` ScrapeQuestion string `short:"q" long:"scrape_question" description:"Search question using Jina AI"` Seed int `short:"e" long:"seed" description:"Seed to be used for LMM generation"` + Version bool `long:"version" description:"Print current version"` } // Init Initialize flags. returns a Flags struct and an error diff --git a/main.go b/main.go index 6c955d3..61ea3cc 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,11 @@ import ( "github.com/danielmiessler/fabric/cli" ) +// use to get latest tag, go install -ldflags "-X main.version=$(git describe --tags --always)" github.com/danielmiessler/fabric@latest +var version = "dev" // Default version + func main() { - _, err := cli.Cli() + _, err := cli.Cli(version) if err != nil { fmt.Printf("%s\n", err) os.Exit(1)