packages/hyprspace: add --interface, implement for commands: peers, status

This commit is contained in:
Max Headroom 2023-03-24 16:36:13 +01:00
parent 9358527fb5
commit 6826ac254d
4 changed files with 13 additions and 17 deletions

View file

@ -10,18 +10,16 @@ import (
var Peers = cmd.Sub{ var Peers = cmd.Sub{
Name: "peers", Name: "peers",
Short: "List peer connections", Short: "List peer connections",
Args: &PeersArgs{},
Run: PeersRun, Run: PeersRun,
} }
type PeersArgs struct { func PeersRun(r *cmd.Root, c *cmd.Sub) {
InterfaceName string ifName := r.Flags.(*GlobalFlags).InterfaceName
if ifName == "" {
ifName = "hyprspace"
} }
func PeersRun(r *cmd.Root, c *cmd.Sub) { peers := rpc.Peers(ifName)
args := c.Args.(*PeersArgs)
peers := rpc.Peers(args.InterfaceName)
for _, ma := range peers.PeerAddrs { for _, ma := range peers.PeerAddrs {
fmt.Println(ma) fmt.Println(ma)
} }

View file

@ -14,6 +14,7 @@ var appVersion string = "develop"
// GlobalFlags contains the flags for commands. // GlobalFlags contains the flags for commands.
type GlobalFlags struct { type GlobalFlags struct {
Config string `short:"c" long:"config" desc:"Specify a custom config path."` Config string `short:"c" long:"config" desc:"Specify a custom config path."`
InterfaceName string `short:"i" long:"interface" desc:"Interface name."`
} }
// Root is the main command. // Root is the main command.

View file

@ -11,19 +11,16 @@ var Status = cmd.Sub{
Name: "status", Name: "status",
Alias: "s", Alias: "s",
Short: "Display Hyprspace daemon status", Short: "Display Hyprspace daemon status",
Args: &StatusArgs{},
Run: StatusRun, Run: StatusRun,
} }
type StatusArgs struct { func StatusRun(r *cmd.Root, c *cmd.Sub) {
InterfaceName string ifName := r.Flags.(*GlobalFlags).InterfaceName
if ifName == "" {
ifName = "hyprspace"
} }
func StatusRun(r *cmd.Root, c *cmd.Sub) { status := rpc.Status(ifName)
// Parse Command Args
args := c.Args.(*StatusArgs)
status := rpc.Status(args.InterfaceName)
fmt.Println("PeerID:", status.PeerID) fmt.Println("PeerID:", status.PeerID)
fmt.Println("Swarm peers:", status.SwarmPeersCurrent) fmt.Println("Swarm peers:", status.SwarmPeersCurrent)
fmt.Printf("Connected VPN nodes: %d/%d\n", status.NetPeersCurrent, status.NetPeersMax) fmt.Printf("Connected VPN nodes: %d/%d\n", status.NetPeersCurrent, status.NetPeersMax)

View file

@ -10,7 +10,7 @@
}; };
packages.hyprspace = with pkgs; buildGo119Module { packages.hyprspace = with pkgs; buildGo119Module {
pname = "hyprspace"; pname = "hyprspace";
version = "0.6.1"; version = "0.6.2";
src = with inputs.nix-filter.lib; let src = with inputs.nix-filter.lib; let
dirs = map inDirectory; dirs = map inDirectory;