mydev/cmd/port.go
Victor Abrell 47bb2d3a69 Use Gitea module path, add MIT license
Set module to git.abrell.se/victor/mydev so it installs from the
private Gitea host, and add an MIT LICENSE.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 14:41:20 +02:00

29 lines
637 B
Go

package cmd
import (
"fmt"
"os"
"git.abrell.se/victor/mydev/internal/run"
"github.com/spf13/cobra"
)
// port wraps `lsof -i :<port>` (the shell `portcheck`). No config needed.
var portCmd = &cobra.Command{
Use: "port <number>",
Short: "Show what is listening on a port (lsof -i :PORT)",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// lsof exits 1 when nothing is on the port — report that plainly.
if err := run.Stream("", "lsof", "-i", ":"+args[0]); err != nil {
fmt.Printf("nothing listening on :%s\n", args[0])
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(portCmd)
}