Browse Source

Omit riglist command when not built with libhamlib

Martin Hebnes Pedersen 3 years ago
parent
commit
267900a6ee
2 changed files with 37 additions and 18 deletions
  1. 0 18
      main.go
  2. 37 0
      riglist.go

+ 0 - 18
main.go

@@ -114,12 +114,6 @@ var commands = []Command{
 		},
 		HandleFunc: rmsListHandle,
 	},
-	{
-		Str:        "riglist",
-		Usage:      "[search term]",
-		Desc:       "Print/search a list of rigcontrol supported transceivers.",
-		HandleFunc: riglistHandle,
-	},
 	{
 		Str:        "configure",
 		Desc:       "Open configuration file for editing.",
@@ -339,18 +333,6 @@ func helpHandle(args []string) {
 	cmd.PrintUsage()
 }
 
-func riglistHandle(args []string) {
-	term := strings.ToLower(args[0])
-
-	fmt.Print("id\ttransceiver\n")
-	for m, str := range hamlib.Rigs() {
-		if !strings.Contains(strings.ToLower(str), term) {
-			continue
-		}
-		fmt.Printf("%d\t%s\n", m, str)
-	}
-}
-
 func cleanup() {
 	for method, _ := range listeners {
 		Unlisten(method)

+ 37 - 0
riglist.go

@@ -0,0 +1,37 @@
+// Copyright 2016 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
+// Use of this source code is governed by the MIT-license that can be
+// found in the LICENSE file.
+
+// +build libhamlib
+
+package main
+
+import (
+	"fmt"
+	"strings"
+
+	"github.com/la5nta/wl2k-go/rigcontrol/hamlib"
+)
+
+func init() {
+	cmd := Command{
+		Str:        "riglist",
+		Usage:      "[search term]",
+		Desc:       "Print/search a list of rigcontrol supported transceivers.",
+		HandleFunc: riglistHandle,
+	}
+
+	commands = append(commands[:8], append([]Command{cmd}, commands[8:]...)...)
+}
+
+func riglistHandle(args []string) {
+	term := strings.ToLower(args[0])
+
+	fmt.Print("id\ttransceiver\n")
+	for m, str := range hamlib.Rigs() {
+		if !strings.Contains(strings.ToLower(str), term) {
+			continue
+		}
+		fmt.Printf("%d\t%s\n", m, str)
+	}
+}