2023-01-15 04:52:47 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(volumeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
var volumeCmd = &cobra.Command{
|
2023-01-15 07:04:48 +00:00
|
|
|
Use: "volume",
|
|
|
|
Short: "sets the volume",
|
|
|
|
Aliases: []string{"v"},
|
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
|
Long: `Sets the volume to the given percent [0-100] or increases/decreases by 5 percent if you say up or down`,
|
2023-01-15 04:52:47 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
if args[0] == "up" {
|
2023-02-17 22:08:25 +00:00
|
|
|
err := commands.ChangeVolume(ctx, 5)
|
2023-01-15 04:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if args[0] == "down" {
|
2023-02-17 22:08:25 +00:00
|
|
|
err := commands.ChangeVolume(ctx, -5)
|
2023-01-15 04:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
vol, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-17 22:08:25 +00:00
|
|
|
err = commands.SetVolume(ctx, vol)
|
2023-01-15 04:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|