-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecutor.go
64 lines (51 loc) · 1.34 KB
/
executor.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/indiependente/autoEqMac/server"
)
// NewExecutor returns a new prompt.Executor.
func NewExecutor(srv *server.HTTPServer) func(string) {
return func(s string) {
s = strings.TrimSpace(s)
if s == "bye" || s == "quit" {
fmt.Println("Bye!")
os.Exit(0)
return
}
headphones := s
fmt.Printf("👉 You selected: %s\n", headphones)
eqMeta, err := srv.GetEQMetadataByName(headphones)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "⛔️ could not find EQ data for headphones %s: %q\n", headphones, err)
os.Exit(1)
return
}
eqPreset, err := srv.GetFixedBandEQPreset(eqMeta.ID)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "⛔️ could not find fixed band EQ preset: %q\n", err)
os.Exit(1)
return
}
filename := filepath.Clean(filename(file, headphones))
f, err := os.Create(filename)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "⛔️ could not create preset file: %q\n", err)
os.Exit(1)
return
}
defer f.Close() //nolint: errcheck,gosec
err = srv.WritePreset(f, eqPreset)
if err != nil {
_ = f.Close()
_ = os.Remove(filename)
_, _ = fmt.Fprintf(os.Stderr, "⛔️ could not write preset to file: %q\n", err)
os.Exit(1)
return
}
fmt.Printf("📝 Preset saved to %s\n", f.Name())
os.Exit(0)
}
}