fix: #986 implement --version flag
This commit is contained in:
parent
dd83d7faca
commit
ea323c12ff
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -64,7 +64,7 @@ jobs:
|
|||||||
GOOS: ${{ env.OS }}
|
GOOS: ${{ env.OS }}
|
||||||
GOARCH: ${{ matrix.arch }}
|
GOARCH: ${{ matrix.arch }}
|
||||||
run: |
|
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
|
- name: Build binary on Windows
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
@ -72,7 +72,7 @@ jobs:
|
|||||||
GOOS: windows
|
GOOS: windows
|
||||||
GOARCH: ${{ matrix.arch }}
|
GOARCH: ${{ matrix.arch }}
|
||||||
run: |
|
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
|
- name: Upload build artifact
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
|
@ -117,7 +117,7 @@ To install Fabric, [make sure Go is installed](https://go.dev/doc/install), and
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install Fabric directly from the repo
|
# 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
|
### Environment Variables
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Cli Controls the cli. It takes in the flags and runs the appropriate functions
|
// 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
|
var currentFlags *Flags
|
||||||
if currentFlags, err = Init(); err != nil {
|
if currentFlags, err = Init(); err != nil {
|
||||||
// we need to reset error, because we don't want to show double help messages
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if currentFlags.Version {
|
||||||
|
fmt.Println(version)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var homedir string
|
var homedir string
|
||||||
if homedir, err = os.UserHomeDir(); err != nil {
|
if homedir, err = os.UserHomeDir(); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -45,6 +45,7 @@ type Flags struct {
|
|||||||
ScrapeURL string `short:"u" long:"scrape_url" description:"Scrape website URL to markdown using Jina AI"`
|
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"`
|
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"`
|
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
|
// Init Initialize flags. returns a Flags struct and an error
|
||||||
|
5
main.go
5
main.go
@ -7,8 +7,11 @@ import (
|
|||||||
"github.com/danielmiessler/fabric/cli"
|
"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() {
|
func main() {
|
||||||
_, err := cli.Cli()
|
_, err := cli.Cli(version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s\n", err)
|
fmt.Printf("%s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user