-
Notifications
You must be signed in to change notification settings - Fork 1
/
midimap.go
44 lines (39 loc) · 826 Bytes
/
midimap.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
package main
import (
"errors"
"fmt"
"os"
"strings"
)
func main() {
err := mainish()
if err != nil {
if err != errUsage {
fmt.Print("error: ")
}
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
// mainish is like main, except if it encounters an error it returns it instead of presenting it to the user.
func mainish() error {
if len(os.Args) < 2 {
return errUsage
}
switch os.Args[1] {
case "ports":
return portsCommandModifier(os.Args[2:])
case "map":
return mapCommandModifier(os.Args[2:])
case "log":
return logCommandModifier(os.Args[2:])
default:
return errUsage
}
}
var errUsage = errors.New(strings.TrimSpace(`
usage: midimap ports
midimap map portnumber mapname
midimap log portnumber [matcher]`))
// midimap map portnumber mapname
// midimap log portnumber [matcher]`))