-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
94 lines (77 loc) · 1.7 KB
/
main.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"os"
"strings"
"github.com/oxodao/metaprint/config"
"github.com/oxodao/metaprint/pulse"
)
var (
AUTHOR = "Oxodao"
VERSION = "DEV"
COMMIT = "XXXXXXXXX"
SOFTWARE_NAME = "metaprint"
)
var otherCommands = []string{"pulseaudio-infos", "version"}
func main() {
cfg := config.Load()
hasOtherCommands := hasOtherCommand()
if len(os.Args) < 3 && !hasOtherCommands {
printUsage()
os.Exit(1)
}
if hasOtherCommands {
switch os.Args[1] {
case "pulseaudio-infos":
pulse.PrintInfos()
case "version":
fmt.Printf("%v %v (Commit %v) by %v\nhttps://github.com/%v/%v\n", SOFTWARE_NAME, VERSION, COMMIT, AUTHOR, strings.ToLower(AUTHOR), strings.ToLower(SOFTWARE_NAME))
os.Exit(1)
default:
printUsage()
os.Exit(1)
}
return
}
module, err := cfg.FindModule(os.Args[1], os.Args[2])
if module == nil && err == nil {
printUsage()
return
} else if module == nil {
fmt.Println(err)
os.Exit(1)
}
text := module.Print(os.Args[3:])
if len(module.GetPrefix()) > 0 {
text = module.GetPrefix() + " " + text
}
if len(module.GetSuffix()) > 0 {
text += " " + module.GetSuffix()
}
fmt.Println(text)
}
func printUsage() {
fmt.Println("Usage: metaprint <module> <name> [params]")
fmt.Println(" metaprint other-command")
fmt.Println()
fmt.Println("Other commands: ")
for _, cmd := range otherCommands {
fmt.Println("\t- " + cmd)
}
fmt.Println()
fmt.Println("Available modules: ")
for _, mod := range config.GetModulesAvailable() {
fmt.Println("\t- " + mod)
}
}
func hasOtherCommand() bool {
if len(os.Args) != 2 {
return false
}
for _, val := range otherCommands {
if os.Args[1] == val {
return true
}
}
return false
}