gospt/src/cmd/volume.go

49 lines
900 B
Go
Raw Normal View History

2023-01-15 04:52:47 +00:00
package cmd
import (
"strconv"
2023-02-09 07:28:41 +00:00
"gitea.asdf.cafe/abs3nt/gospt/src/commands"
2023-01-15 04:52:47 +00:00
"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" {
err := commands.ChangeVolume(ctx, client, 5)
if err != nil {
return err
}
return nil
}
if args[0] == "down" {
err := commands.ChangeVolume(ctx, client, -5)
if err != nil {
return err
}
return nil
}
vol, err := strconv.Atoi(args[0])
if err != nil {
return err
}
err = commands.SetVolume(ctx, client, vol)
if err != nil {
return err
}
return nil
},
}