Skip to content

Commit

Permalink
Add version command (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhbert authored Sep 3, 2024
1 parent 034338a commit 20ae999
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ vars:
VERSION:
sh: git describe --tags | sed -r 's/-.+//'


tasks:
prepare:
desc: 'Create folder for results of building'
Expand Down Expand Up @@ -61,12 +62,12 @@ tasks:
build:
desc: 'Build for the current platform'
cmds:
- go build .
- go build -ldflags="-X 'colligendis/cmd/version.Version={{ .VERSION }}'" .
build-loop:
cmds:
- |
rm -rf temp && mkdir temp
{{ .GOOS }} {{ .GOARCH }} go build -o temp/colligendis{{ if .WIN }}.exe{{ end }}
{{ .GOOS }} {{ .GOARCH }} go build -o -ldflags="-X 'colligendis/cmd/version.Version={{ .VERSION }}'" temp/colligendis{{ if .WIN }}.exe{{ end }}
cp LICENSE temp/LICENSE{{ if .WIN }}.txt{{ end }}
cp docs/INSTALL temp/INSTALL{{ if .WIN }}.txt{{ end }}
cd temp
Expand Down
2 changes: 2 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"colligendis/cmd/common"
"colligendis/cmd/config"
"colligendis/cmd/load"
"colligendis/cmd/version"
"colligendis/cmd/view"
"colligendis/internal/common/structs"
"os"
Expand All @@ -52,6 +53,7 @@ func createRootCommand(flags *common.ColligendisFlags, tmpls []structs.TemplateS
cmd.AddCommand(load.GetLoadCommand(flags))
cmd.AddCommand(config.GetConfigCommand(flags))
cmd.AddCommand(view.GetViewCommand(flags))
cmd.AddCommand(version.GetVersionCommand(flags))

cmd.PersistentFlags().BoolVarP(&flags.ViewMode, "verbose", "v", false, "Show the full report of the commands")

Expand Down
23 changes: 23 additions & 0 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package version

import (
"colligendis/cmd/common"
"fmt"
"github.com/spf13/cobra"
)

var (
Version = "dev"
)

func GetVersionCommand(flags *common.ColligendisFlags) *cobra.Command {
var cmd = &cobra.Command{
Use: "version",
Short: "Displaying version of utility",
Example: `colligendis version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version)
},
}
return cmd
}

0 comments on commit 20ae999

Please sign in to comment.