Skip to content

Commit

Permalink
Decouple version into its own package
Browse files Browse the repository at this point in the history
This allows us to import the package and use version
elsewhere throughout the codebase and set the right version
during the release via build flags.
  • Loading branch information
radeksimko committed Mar 24, 2020
1 parent ee5c5ac commit b3577e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"os"

"github.com/hashicorp/terraform-ls/commands"
"github.com/hashicorp/terraform-ls/version"
"github.com/mitchellh/cli"
)

func main() {
c := &cli.CLI{
Name: "terraform-ls",
Version: "0.1.0",
Version: version.String(),
Args: os.Args[1:],
}

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

import (
"fmt"

version "github.com/hashicorp/go-version"
)

// The main version number that is being run at the moment.
var Version = "0.1.0"

// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
var Prerelease = "dev"

// SemVer is an instance of version.Version. This has the secondary
// benefit of verifying during tests and init time that our version is a
// proper semantic version, which should always be the case.
var SemVer *version.Version

func init() {
SemVer = version.Must(version.NewVersion(Version))
}

// ServerName is the name used to send to clients as a way
// to identify itself in the LSP
const ServerName = "hashicorp/terraform-ls"

// String returns the complete version string, including prerelease
func String() string {
if Prerelease != "" {
return fmt.Sprintf("%s-%s", Version, Prerelease)
}
return Version
}

0 comments on commit b3577e9

Please sign in to comment.