Refactor the CLI markup code to make it re-useable

This commit is contained in:
Kovid Goyal
2022-09-18 14:07:28 +05:30
parent 8796168469
commit 1ff4f2df4f
3 changed files with 233 additions and 185 deletions

24
tools/utils/hostname.go Normal file
View File

@@ -0,0 +1,24 @@
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
package utils
import (
"fmt"
"os"
)
var _ = fmt.Print
var hostname string = "*"
func CachedHostname() string {
if hostname == "*" {
h, err := os.Hostname()
if err != nil {
hostname = h
} else {
hostname = ""
}
}
return hostname
}