File: command.go

package info (click to toggle)
amfora 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,272 kB
  • sloc: python: 71; sh: 42; makefile: 39
file content (35 lines) | stat: -rw-r--r-- 696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package display

import (
	"strconv"

	"github.com/makeworld-the-better-one/amfora/command"
	"github.com/spf13/viper"
)

// CustomCommand runs custom commands as defined in the app configuration.
// Commands are zero-indexed, so 0 is command1 and 9 is command0 (10).
func CustomCommand(num int, url string) {
	if num < 0 {
		num = 0
	}
	num++
	if num > 9 {
		num = 0
	}

	cmd := viper.GetString("commands.command" + strconv.Itoa(num))
	if len(cmd) > 0 {
		msg, err := command.RunCommand(cmd, url)
		if err != nil {
			go Error("Command Error", err.Error())
			return
		}
		go Info(msg)
	} else {
		go Error("Command Error", "Command "+strconv.Itoa(num)+" not defined")
		return
	}

	App.Draw()
}