156 lines
4.7 KiB
Go
156 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
`embed`
|
|
"strings"
|
|
`text/template`
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
var (
|
|
args = new(Args)
|
|
validate = validator.New(validator.WithRequiredStructEnabled())
|
|
)
|
|
|
|
const (
|
|
/*
|
|
fixedPad is a fixed "surrounding" pad always present (as minimum), even for values max len on columns.
|
|
*Must* be positive even, as <fixed left pad> and <fixed right pad> == fixedPad/2.
|
|
*/
|
|
fixedPad int = 2
|
|
/*
|
|
padChars is what fills the pads in table cells.
|
|
At the *LEAST*, a cell will be "<fixedPad/2 * padChars><str><fixedPad/2 * padChars>"
|
|
*/
|
|
padChars string = " "
|
|
)
|
|
|
|
var (
|
|
//go:embed "_tpl"
|
|
tplDir embed.FS
|
|
tblTpl *template.Template = template.Must(template.New("").Funcs(
|
|
template.FuncMap{
|
|
"bold": tplFmtBold,
|
|
"legacy4": tplTableLegacy4,
|
|
"mask4": tplTableMasks4,
|
|
"notes": tplTableNotes,
|
|
"prefixes": tplTablePrefixes,
|
|
},
|
|
).ParseFS(tplDir, "_tpl/*.tpl"))
|
|
)
|
|
|
|
var (
|
|
// Primarily output formatting stuff in this block.
|
|
sectSepCnt = 48
|
|
// sectFmts contains a lookup of map[<is plain>][]string{<level 1>, <level 2>, <level 3>}
|
|
sectFmts map[bool][]string = map[bool][]string{
|
|
true: []string{
|
|
strings.Repeat("=", sectSepCnt),
|
|
strings.Repeat("-", sectSepCnt),
|
|
strings.Repeat(".", sectSepCnt),
|
|
},
|
|
false: []string{
|
|
strings.Repeat("━", sectSepCnt),
|
|
strings.Repeat("─", sectSepCnt),
|
|
strings.Repeat("╍", sectSepCnt),
|
|
},
|
|
}
|
|
// tblFmts contains a lookup of map[<is plain>]*tableFormatter.
|
|
tblFmts map[bool]*tableFormatter = map[bool]*tableFormatter{
|
|
// Plaintext/ASCII-only
|
|
true: &tableFormatter{
|
|
TopLeftHdr: "*", // Or _
|
|
TopFillHdr: "*", // ""
|
|
TopColSepHdr: "*", // ""
|
|
TopRightHdr: "*", // ""
|
|
ColSepHdr: "|",
|
|
BottomLeftHdr: "*", // Or +
|
|
BottomFillHdr: "*", // Or -
|
|
BottomColSepHdr: "*", // Or +
|
|
BottomRightHdr: "*", // ""
|
|
Left: "|",
|
|
Fill: "-",
|
|
LineColSep: "|",
|
|
LineLeft: "|",
|
|
LineRight: "|",
|
|
ColSep: "|",
|
|
Right: "|",
|
|
LastLeft: "+",
|
|
LastFill: "-",
|
|
LastSep: "-",
|
|
LastRight: "+",
|
|
SuppressLineSep: true,
|
|
NoUpperTitle: false,
|
|
NoBoldTitle: true,
|
|
},
|
|
// Unicode/UTF-8
|
|
// https://en.wikipedia.org/wiki/Box-drawing_characters
|
|
false: &tableFormatter{
|
|
TopLeftHdr: "┏",
|
|
TopFillHdr: "━",
|
|
TopColSepHdr: "┳",
|
|
TopRightHdr: "┓",
|
|
ColSepHdr: "┃",
|
|
BottomLeftHdr: "┣",
|
|
BottomFillHdr: "━",
|
|
BottomColSepHdr: "╇",
|
|
BottomRightHdr: "┫",
|
|
Left: "┃",
|
|
Fill: "─",
|
|
LineColSep: "┼",
|
|
LineLeft: "┠",
|
|
LineRight: "┨",
|
|
ColSep: "│",
|
|
Right: "┃",
|
|
LastLeft: "┗",
|
|
LastFill: "━",
|
|
LastSep: "┷",
|
|
LastRight: "┛",
|
|
SuppressLineSep: false,
|
|
NoUpperTitle: true,
|
|
NoBoldTitle: false,
|
|
},
|
|
}
|
|
)
|
|
|
|
var (
|
|
// netNotes is keyed first on IP/inet family version (4/6) and then the prefix size.
|
|
netNotes map[uint8]map[uint8]string = map[uint8]map[uint8]string{
|
|
4: map[uint8]string{
|
|
32: "Host route/single host",
|
|
31: "PTP link",
|
|
30: "PTP (legacy/compatibility)",
|
|
29: "Smallest multi-host network size possible",
|
|
28: "Typical/common size for small LANs/VLANs",
|
|
27: "Typical/common size for small LANs/VLANs",
|
|
26: "Typical/common size for small LANs/VLANs",
|
|
25: "Typical/common size for large LANs/VLANs",
|
|
24: "Typical/common size for large LANs/VLANs",
|
|
22: "Typical/common size for smaller business networks",
|
|
21: "Typical/common size for larger business networks, smaller ISPs",
|
|
20: "Typical/common size for larger business networks, smaller ISPs",
|
|
19: "Typical/common size for enterprise business networks, larger ISPs",
|
|
18: "Typical/common size for enterprise business networks, larger ISPs",
|
|
17: "Typical/common size for enterprise business networks, larger ISPs",
|
|
8: "Largest IANA block allocation size possible",
|
|
0: "Entire IPv4 Internet address prefix; commonly used to indicate default route",
|
|
},
|
|
6: map[uint8]string{
|
|
128: "Host route/single host, single endpoints, and loopback (::1/128 explicitly)",
|
|
127: "Point-to-Point link (inter-router)",
|
|
64: "Single LAN; default prefix size for SLAAC",
|
|
60: "Some (very limited) 6rd networks",
|
|
56: "Minimum end site assignment (RFC 6177)",
|
|
48: "Typical/common assignment for larger sites",
|
|
36: "Possible future LIR \"extra-small\" allocation",
|
|
32: "\"Minimal\" LIR allocation",
|
|
28: "\"Medium\" LIR allocation",
|
|
24: "\"Large\" LIR allocation",
|
|
20: "\"Extra-large\" LIR allocation",
|
|
12: "RIR allocation from IANA",
|
|
0: "Entire IPv6 Internet address prefix; commonly used to represent default route",
|
|
},
|
|
}
|
|
)
|