all or some

This commit is contained in:
root 2025-06-25 17:25:05 -04:00
parent a7775c999c
commit 25ca294287
2 changed files with 34 additions and 0 deletions

BIN
main

Binary file not shown.

34
main.go
View File

@ -1,6 +1,8 @@
package main
import (
"flag"
"strings"
"fmt"
"io/ioutil"
"net"
@ -12,7 +14,33 @@ import (
"golang.org/x/sys/unix"
)
type stringSlice []string
func (s *stringSlice) String() string {
return strings.Join(*s, ",")
}
func (s *stringSlice) Set(value string) error {
*s = append(*s, value)
return nil
}
func main() {
var interfaces stringSlice
flag.Var(&interfaces, "iface", "Interface(s) to filter on (can be specified multiple times)")
flag.Parse()
// Build lookup map
filterSet := make(map[string]struct{})
for _, name := range interfaces {
filterSet[name] = struct{}{}
}
// Determine if we are filtering at all
filtering := len(filterSet) > 0
headerStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("63"))
ipStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("203"))
upStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42"))
@ -33,12 +61,18 @@ func main() {
return
}
for _, link := range links {
attrs := link.Attrs()
if attrs == nil {
continue
}
if filtering {
if _, ok := filterSet[attrs.Name]; !ok {
continue
}
}
state := downStyle.Render("DOWN")
if attrs.Flags&net.FlagUp != 0 {
state = upStyle.Render("UP")