-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume.go
52 lines (47 loc) · 951 Bytes
/
volume.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
package control
import (
"fmt"
"strconv"
"github.com/urfave/cli"
"github.com/robertgzr/xap/mp"
)
var volumeCommand = cli.Command{
Name: "vol",
ArgsUsage: "[[+|-]VALUE]",
Category: "CONTROL",
Usage: "Print and adjust the softvol property",
SkipFlagParsing: true,
Action: func(ctx *cli.Context) error {
c, err := mp.Connect(ctx)
if err != nil {
return err
}
arg := ctx.Args().First()
switch arg {
case "":
vol, err := c.Volume()
if err != nil {
return err
}
fmt.Printf("VOLUME:\n| %v\n", vol)
return nil
case "-h":
fallthrough
case "--help":
return cli.ShowCommandHelp(ctx, "vol")
default:
val, err := strconv.ParseFloat(arg[1:], 64)
if err != nil {
return err
}
switch arg[:1] {
case "+":
return c.VolumeUp(val)
case "-":
return c.VolumeDown(val)
default:
return fmt.Errorf("missing + or - before VALUE")
}
}
},
}