From 6826ac254ddd0a323b80126de63a7ca3436ee758 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Mar 2023 16:36:13 +0100 Subject: [PATCH] packages/hyprspace: add --interface, implement for commands: peers, status --- packages/networking/hyprspace/cli/peers.go | 12 +++++------- packages/networking/hyprspace/cli/root.go | 3 ++- packages/networking/hyprspace/cli/status.go | 13 +++++-------- packages/networking/hyprspace/project.nix | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/networking/hyprspace/cli/peers.go b/packages/networking/hyprspace/cli/peers.go index 7d41bfc..93df1d9 100644 --- a/packages/networking/hyprspace/cli/peers.go +++ b/packages/networking/hyprspace/cli/peers.go @@ -10,18 +10,16 @@ import ( var Peers = cmd.Sub{ Name: "peers", Short: "List peer connections", - Args: &PeersArgs{}, Run: PeersRun, } -type PeersArgs struct { - InterfaceName string -} - func PeersRun(r *cmd.Root, c *cmd.Sub) { - args := c.Args.(*PeersArgs) + ifName := r.Flags.(*GlobalFlags).InterfaceName + if ifName == "" { + ifName = "hyprspace" + } - peers := rpc.Peers(args.InterfaceName) + peers := rpc.Peers(ifName) for _, ma := range peers.PeerAddrs { fmt.Println(ma) } diff --git a/packages/networking/hyprspace/cli/root.go b/packages/networking/hyprspace/cli/root.go index 560d6b6..7dc9bf7 100644 --- a/packages/networking/hyprspace/cli/root.go +++ b/packages/networking/hyprspace/cli/root.go @@ -13,7 +13,8 @@ var appVersion string = "develop" // GlobalFlags contains the flags for commands. 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. diff --git a/packages/networking/hyprspace/cli/status.go b/packages/networking/hyprspace/cli/status.go index bd67645..e8bae14 100644 --- a/packages/networking/hyprspace/cli/status.go +++ b/packages/networking/hyprspace/cli/status.go @@ -11,19 +11,16 @@ var Status = cmd.Sub{ Name: "status", Alias: "s", Short: "Display Hyprspace daemon status", - Args: &StatusArgs{}, Run: StatusRun, } -type StatusArgs struct { - InterfaceName string -} - func StatusRun(r *cmd.Root, c *cmd.Sub) { - // Parse Command Args - args := c.Args.(*StatusArgs) + ifName := r.Flags.(*GlobalFlags).InterfaceName + if ifName == "" { + ifName = "hyprspace" + } - status := rpc.Status(args.InterfaceName) + status := rpc.Status(ifName) fmt.Println("PeerID:", status.PeerID) fmt.Println("Swarm peers:", status.SwarmPeersCurrent) fmt.Printf("Connected VPN nodes: %d/%d\n", status.NetPeersCurrent, status.NetPeersMax) diff --git a/packages/networking/hyprspace/project.nix b/packages/networking/hyprspace/project.nix index a891952..79ae6ff 100644 --- a/packages/networking/hyprspace/project.nix +++ b/packages/networking/hyprspace/project.nix @@ -10,7 +10,7 @@ }; packages.hyprspace = with pkgs; buildGo119Module { pname = "hyprspace"; - version = "0.6.1"; + version = "0.6.2"; src = with inputs.nix-filter.lib; let dirs = map inDirectory;