-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build/cmd): include commit/tag and time in 'version' cmd
uses tag if it matches the current commit, or the latest commit otherwise. fixes #113 Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
6 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bytesparadise/libasciidoc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewVersionCmd returns the root command | ||
func NewVersionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of libasciidoc", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if libasciidoc.BuildTag != "" { | ||
fmt.Fprintf(cmd.OutOrStdout(), "tag: %s\n", libasciidoc.BuildTag) | ||
} else { | ||
fmt.Fprintf(cmd.OutOrStdout(), "commit: %s\n", libasciidoc.BuildCommit) | ||
} | ||
fmt.Fprintf(cmd.OutOrStdout(), "build time: %s\n", libasciidoc.BuildTime) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main_test | ||
|
||
import ( | ||
"bytes" | ||
|
||
main "github.com/bytesparadise/libasciidoc/cmd/libasciidoc" | ||
. "github.com/onsi/ginkgo" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var _ = Describe("version cmd", func() { | ||
|
||
It("ok", func() { | ||
// given | ||
versionCmd := main.NewVersionCmd() | ||
buf := new(bytes.Buffer) | ||
versionCmd.SetOutput(buf) | ||
versionCmd.SetArgs([]string{}) | ||
// when | ||
err := versionCmd.Execute() | ||
// then | ||
require.NoError(GinkgoT(), err) | ||
require.NotEmpty(GinkgoT(), buf.String()) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters