Skip to content

Commit

Permalink
feat: Add functionality to display the current version of labdoc via …
Browse files Browse the repository at this point in the history
…the `--version` flag
  • Loading branch information
erNail committed Jun 15, 2024
1 parent 741d274 commit f4d96fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ before:
- "go mod tidy"

builds:

- env:
- "CGO_ENABLED=0"
goos:
Expand All @@ -15,6 +14,8 @@ builds:
goarch:
- "amd64"
- "arm64"
ldflags:
- "-s -w -X github.com/erNail/labdoc/cmd.version={{ .Version }}"

# Container Image build
kos:
Expand Down
10 changes: 7 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import (
"github.com/spf13/cobra"
)

// This will be set during the build via `-ldflags "-s -w -X github.com/erNail/labdoc/cmd.version={{ .Version }}"`.
var version = "dev"

// NewRootCmd creates the root command for the CLI application.
// This command serves as the entry point and parent for all other commands.
//
// Returns:
// - *cobra.Command: A pointer to the newly created cobra.Command.
func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "labdoc",
Short: "Generate Markdown documentation from GitLab CI/CD Components",
Long: "A CLI tool for generating Markdown documentation from GitLab CI/CD Components",
Use: "labdoc",
Short: "Generate Markdown documentation from GitLab CI/CD Components",
Long: "A CLI tool for generating Markdown documentation from GitLab CI/CD Components",
Version: version,
}

filesystem := afero.NewOsFs()
Expand Down
11 changes: 11 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ func TestRootCmdPrintsHelpWithoutError(t *testing.T) {
require.NoError(t, err)
}

func TestRootCmdPrintsVersionWithoutError(t *testing.T) {
t.Parallel()

cmd := NewRootCmd()
cmd.SetArgs([]string{"--version"})

err := cmd.Execute()

require.NoError(t, err)
}

func TestRootCmdCallsGenerateSubcommand(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ tasks:
cmds:
- "semantic-release --dry-run"

test-version-ldflags:
cmds:
- "go run -ldflags '-s -w -X github.com/erNail/labdoc/cmd.version=v1.2.3' main.go --version"

test-github-actions:
cmds:
- "act"
Expand Down

0 comments on commit f4d96fc

Please sign in to comment.