gospt/src/cmd/seek.go

50 lines
961 B
Go
Raw Normal View History

2023-01-15 04:52:47 +00:00
package cmd
import (
"strconv"
"gospt/src/commands"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(seekCmd)
}
var seekCmd = &cobra.Command{
2023-01-15 07:04:48 +00:00
Use: "seek {forward/backward/songposition in seconds}",
Short: "seek forward/backward or to a given second",
Aliases: []string{"s"},
Args: cobra.MinimumNArgs(1),
Long: `Seeks forward or backward, or seeks to a given position in seconds`,
2023-01-15 04:52:47 +00:00
RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "forward" || args[0] == "f" {
err := commands.Seek(ctx, client, true)
if err != nil {
return err
}
return nil
}
if args[0] == "backward" || args[0] == "b" {
err := commands.Seek(ctx, client, false)
if err != nil {
return err
}
return nil
}
pos, err := strconv.Atoi(args[0])
if err != nil {
return err
}
pos = pos * 1000
err = commands.SetPosition(ctx, client, pos)
if err != nil {
return err
}
return nil
},
}