mirror of
https://github.com/rkfg/regolancer
synced 2024-11-15 00:15:27 +00:00
add go build flags
This commit is contained in:
parent
2445c77fc9
commit
e66a8c9d3c
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package helpmessage
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -40,7 +39,7 @@ type Options struct {
|
||||
options []*Option
|
||||
}
|
||||
|
||||
func scanStruct(realval reflect.Value, opt *Options) error {
|
||||
func ScanStruct(realval reflect.Value, opt *Options) error {
|
||||
|
||||
stype := realval.Type()
|
||||
|
||||
@ -144,14 +143,6 @@ func getAlignmentInfo(options *Options, p *flags.Parser) alignmentInfo {
|
||||
return ret
|
||||
}
|
||||
|
||||
func getTerminalColumns() int {
|
||||
ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ)
|
||||
if err != nil {
|
||||
return 80
|
||||
}
|
||||
return int(ws.Col)
|
||||
}
|
||||
|
||||
type alignmentInfo struct {
|
||||
maxLongLen int
|
||||
hasShort bool
|
16
helpmessage/termsize.go
Normal file
16
helpmessage/termsize.go
Normal file
@ -0,0 +1,16 @@
|
||||
//go:build !windows && !plan9 && !appengine && !wasm
|
||||
// +build !windows,!plan9,!appengine,!wasm
|
||||
|
||||
package helpmessage
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func getTerminalColumns() int {
|
||||
ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ)
|
||||
if err != nil {
|
||||
return 80
|
||||
}
|
||||
return int(ws.Col)
|
||||
}
|
8
helpmessage/termsize_nosysioctl.go
Normal file
8
helpmessage/termsize_nosysioctl.go
Normal file
@ -0,0 +1,8 @@
|
||||
//go:build plan9 || appengine || wasm
|
||||
// +build plan9 appengine wasm
|
||||
|
||||
package helpmessage
|
||||
|
||||
func getTerminalColumns() int {
|
||||
return 80
|
||||
}
|
86
helpmessage/termsize_windows.go
Normal file
86
helpmessage/termsize_windows.go
Normal file
@ -0,0 +1,86 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package helpmessage
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type (
|
||||
SHORT int16
|
||||
WORD uint16
|
||||
|
||||
SMALL_RECT struct {
|
||||
Left SHORT
|
||||
Top SHORT
|
||||
Right SHORT
|
||||
Bottom SHORT
|
||||
}
|
||||
|
||||
COORD struct {
|
||||
X SHORT
|
||||
Y SHORT
|
||||
}
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO struct {
|
||||
Size COORD
|
||||
CursorPosition COORD
|
||||
Attributes WORD
|
||||
Window SMALL_RECT
|
||||
MaximumWindowSize COORD
|
||||
}
|
||||
)
|
||||
|
||||
var kernel32DLL = syscall.NewLazyDLL("kernel32.dll")
|
||||
var getConsoleScreenBufferInfoProc = kernel32DLL.NewProc("GetConsoleScreenBufferInfo")
|
||||
|
||||
func getError(r1, r2 uintptr, lastErr error) error {
|
||||
// If the function fails, the return value is zero.
|
||||
if r1 == 0 {
|
||||
if lastErr != nil {
|
||||
return lastErr
|
||||
}
|
||||
return syscall.EINVAL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getStdHandle(stdhandle int) (uintptr, error) {
|
||||
handle, err := syscall.GetStdHandle(stdhandle)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uintptr(handle), nil
|
||||
}
|
||||
|
||||
// GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer.
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
|
||||
func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) {
|
||||
var info CONSOLE_SCREEN_BUFFER_INFO
|
||||
if err := getError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func getTerminalColumns() int {
|
||||
defaultWidth := 80
|
||||
|
||||
stdoutHandle, err := getStdHandle(syscall.STD_OUTPUT_HANDLE)
|
||||
if err != nil {
|
||||
return defaultWidth
|
||||
}
|
||||
|
||||
info, err := GetConsoleScreenBufferInfo(stdoutHandle)
|
||||
if err != nil {
|
||||
return defaultWidth
|
||||
}
|
||||
|
||||
if info.MaximumWindowSize.X > 0 {
|
||||
return int(info.MaximumWindowSize.X)
|
||||
}
|
||||
|
||||
return defaultWidth
|
||||
}
|
7
main.go
7
main.go
@ -20,6 +20,7 @@ import (
|
||||
"github.com/lightninglabs/lndclient"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/rkfg/regolancer/helpmessage"
|
||||
)
|
||||
|
||||
type configParams struct {
|
||||
@ -465,16 +466,16 @@ func main() {
|
||||
|
||||
// Print own Help message instead of using the builtin Help function of goflags to group output
|
||||
if params.Help {
|
||||
var opt Options
|
||||
var opt helpmessage.Options
|
||||
if reflect.ValueOf(params).Kind() == reflect.Struct {
|
||||
v := reflect.ValueOf(params)
|
||||
err := scanStruct(v, &opt)
|
||||
err := helpmessage.ScanStruct(v, &opt)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var b bytes.Buffer
|
||||
WriteHelp(&opt, parser, &b)
|
||||
helpmessage.WriteHelp(&opt, parser, &b)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user