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

Add version command #10

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
}