Skip to content

Commit 2e596e2

Browse files
committed
terminal+make: encode and print LiT version
Fixes #328 by encoding the LiT version and also printing it on startup.
1 parent 80ee9ae commit 2e596e2

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ make_ldflags = $(2) -X $(LND_PKG)/build.Commit=lightning-terminal-$(COMMIT) \
6060
-X $(LND_PKG)/build.GoVersion=$(GOVERSION) \
6161
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g') \
6262
-X $(PKG).appFilesPrefix=$(PUBLIC_URL) \
63+
-X $(PKG).Commit=$(COMMIT) \
6364
-X $(LOOP_PKG).Commit=$(LOOP_COMMIT) \
6465
-X $(POOL_PKG).Commit=$(POOL_COMMIT)
6566

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Lightning Terminal is backwards compatible with `lnd` back to version v0.13.3-be
7070

7171
| LiT | LND |
7272
|------------------| ------------ |
73+
| **v0.6.4-alpha** | v0.13.3-beta |
7374
| **v0.6.3-alpha** | v0.13.3-beta |
7475
| **v0.6.2-alpha** | v0.13.3-beta |
7576
| **v0.6.1-alpha** | v0.13.3-beta |
@@ -113,6 +114,7 @@ The following table shows the supported combinations:
113114

114115
| LiT | LND | Loop | Faraday | Pool |
115116
|------------------|--------------| ----------- | ------------ |--------------|
117+
| **v0.6.4-alpha** | v0.14.2-beta | v0.15.1-beta | v0.2.7-alpha | v0.5.4-alpha |
116118
| **v0.6.3-alpha** | v0.14.2-beta | v0.15.1-beta | v0.2.7-alpha | v0.5.4-alpha |
117119
| **v0.6.2-alpha** | v0.14.1-beta | v0.15.1-beta | v0.2.7-alpha | v0.5.4-alpha |
118120
| **v0.6.1-alpha** | v0.14.1-beta | v0.15.1-beta | v0.2.7-alpha | v0.5.2-alpha |

terminal.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ func (g *LightningTerminal) Run() error {
187187
g.cfg = cfg
188188
g.defaultImplCfg = g.cfg.Lnd.ImplementationConfig(shutdownInterceptor)
189189

190+
// Show version at startup.
191+
log.Infof("LiT version: %s", Version())
192+
190193
// Create the instances of our subservers now so we can hook them up to
191194
// lnd once it's fully started.
192195
bufRpcListener := bufconn.Listen(100)
@@ -1349,14 +1352,15 @@ func (g *LightningTerminal) showStartupInfo() error {
13491352
"----------------------------------------------------------\n" +
13501353
" Lightning Terminal (LiT) by Lightning Labs \n" +
13511354
" \n" +
1352-
" Operating mode %s \n" +
1353-
" Node status %s \n" +
1354-
" Alias %s \n" +
1355-
" Version %s \n" +
1356-
" Web interface %s (open %s in your browser) \n" +
1355+
" LND Operating mode %s \n" +
1356+
" LND Node status %s \n" +
1357+
" LND Alias %s \n" +
1358+
" LND Version %s \n" +
1359+
" LiT Version %s \n" +
1360+
" Web interface %s (open %s in your browser) \n" +
13571361
"----------------------------------------------------------\n"
13581362
fmt.Printf(str, info.mode, info.status, info.alias, info.version,
1359-
listenAddr, info.webURI)
1363+
Version(), listenAddr, info.webURI)
13601364

13611365
return nil
13621366
}

version.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package terminal
2+
3+
// Copyright (c) 2013-2017 The btcsuite developers
4+
// Copyright (c) 2015-2016 The Decred developers
5+
// Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go
6+
// Copyright (C) 2015-2022 The Lightning Network Developers
7+
8+
import (
9+
"bytes"
10+
"fmt"
11+
"strings"
12+
)
13+
14+
// Commit stores the current commit hash of this build, this should be set
15+
// using the -ldflags during compilation.
16+
var Commit string
17+
18+
// semanticAlphabet
19+
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
20+
21+
// These constants define the application version and follow the semantic
22+
// versioning 2.0.0 spec (http://semver.org/).
23+
const (
24+
appMajor uint = 0
25+
appMinor uint = 6
26+
appPatch uint = 4
27+
28+
// appPreRelease MUST only contain characters from semanticAlphabet per
29+
// the semantic versioning spec.
30+
appPreRelease = "alpha"
31+
)
32+
33+
// Version returns the application version as a properly formed string per the
34+
// semantic versioning 2.0.0 spec (http://semver.org/).
35+
func Version() string {
36+
// Start with the major, minor, and patch versions.
37+
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
38+
39+
// Append pre-release version if there is one. The hyphen called for
40+
// by the semantic versioning spec is automatically appended and should
41+
// not be contained in the pre-release string. The pre-release version
42+
// is not appended if it contains invalid characters.
43+
preRelease := normalizeVerString(appPreRelease)
44+
if preRelease != "" {
45+
version = fmt.Sprintf("%s-%s", version, preRelease)
46+
}
47+
48+
// Append commit hash of current build to version.
49+
version = fmt.Sprintf("%s commit=%s", version, Commit)
50+
51+
return version
52+
}
53+
54+
// normalizeVerString returns the passed string stripped of all characters
55+
// which are not valid according to the semantic versioning guidelines for
56+
// pre-release version and build metadata strings. In particular they MUST
57+
// only contain characters in semanticAlphabet.
58+
func normalizeVerString(str string) string {
59+
var result bytes.Buffer
60+
for _, r := range str {
61+
if strings.ContainsRune(semanticAlphabet, r) {
62+
result.WriteRune(r)
63+
}
64+
}
65+
return result.String()
66+
}

0 commit comments

Comments
 (0)