gospt/cmd/seek.go

48 lines
914 B
Go
Raw Normal View History

2023-01-15 04:52:47 +00:00
package cmd
import (
"strconv"
"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" {
2023-02-17 22:08:25 +00:00
err := commands.Seek(ctx, true)
2023-01-15 04:52:47 +00:00
if err != nil {
return err
}
return nil
}
if args[0] == "backward" || args[0] == "b" {
2023-02-17 22:08:25 +00:00
err := commands.Seek(ctx, false)
2023-01-15 04:52:47 +00:00
if err != nil {
return err
}
return nil
}
pos, err := strconv.Atoi(args[0])
if err != nil {
return err
}
pos = pos * 1000
2023-02-17 22:08:25 +00:00
err = commands.SetPosition(ctx, pos)
2023-01-15 04:52:47 +00:00
if err != nil {
return err
}
return nil
},
}