Skip to content

Commit

Permalink
Added -version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
juliosueiras committed Sep 19, 2019
1 parent 3ecb10a commit 211e07c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ builds:
- windows_amd64
main: .
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
- -s -w -X main.Version={{.Version}} -X main.GitCommit={{.FullCommit}} -X main.Date={{.Date}}
binary: terraform-lsp
lang: go
archive:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
default:
go build && cp ./terraform-lsp ~/.bin/ && cp ./terraform-lsp ~/
go build -ldflags "-X main.GitCommit=$$(git rev-list -1 HEAD) -X main.Version=$$(git describe --tags) -X main.Date=$$(date --rfc-3339=date)"

copy:
go build -ldflags "-X main.GitCommit=$$(git rev-list -1 HEAD) -X main.Version=$$(git describe --tags) -X main.Date=$$(date --rfc-3339=date)" && cp ./terraform-lsp ~/.bin/ && cp ./terraform-lsp ~/

.PHONY: copy
9 changes: 8 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ buildGoModule rec {
version = "0.0.9";
src = ./.;

modSha256 = "1mb3169vdlv4h10k15pg88s48s2b6y7v5frk9j9ahg52grygcqb2";
modSha256 = "105kwfb9a501m5swcbgp4z97l43fa1hg3r7vy58zm0f8g54006hi";

buildPhase = ''
runHook preBuild
runHook renameImports
go install -ldflags="-s -w -X main.Version=${version} -X main.GitCommit='omitted' -X main.Date='omitted'"
runHook postBuild
'';

goPackagePath = "github.com/juliosueiras/terraform-lsp";
subPackages = [ "." ];
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ var tempFile *os.File
var location = flag.String("log-location", "", "Location of the lsp log")
var enableLogFile = flag.Bool("enable-log-file", false, "Enable log file")

var Version string
var GitCommit string
var Date string

var version = flag.Bool("version", false, "Show version")

var Server *jrpc2.Server

func Initialize(ctx context.Context, vs lsp.InitializeParams) (lsp.InitializeResult, error) {
Expand Down Expand Up @@ -586,6 +592,11 @@ func TextDocumentPublishDiagnostics(server *jrpc2.Server, ctx context.Context, v
func main() {
flag.Parse()

if *version {
fmt.Printf("v%s, commit: %s, build on: %s", strings.Trim(Version, "v"), GitCommit, Date)
return
}

Server = jrpc2.NewServer(handler.Map{
"initialize": handler.New(Initialize),
"textDocument/completion": handler.New(TextDocumentComplete),
Expand Down

0 comments on commit 211e07c

Please sign in to comment.