pass presets with args

This commit is contained in:
filifa 2024-09-07 19:16:08 -05:00
parent d59a2859b6
commit 6d045ff304
1 changed files with 5 additions and 12 deletions

View File

@ -27,7 +27,6 @@ import (
"github.com/veandco/go-sdl2/sdl"
)
var presets []string
var transition bool
/*
@ -49,8 +48,8 @@ func checkStdin() error {
* validatePresets performs some basic checks on the presets passed in and
* returns an error if it finds a problem.
*/
func validatePresets() error {
for _, p := range presets {
func validatePresets(cmd *cobra.Command, args []string) error {
for _, p := range args {
info, err := os.Stat(p)
if err != nil {
return err
@ -145,12 +144,7 @@ func milkbucket(cmd *cobra.Command, args []string) {
}
defer sdl.Quit()
err = validatePresets()
if err != nil {
log.Fatal(err)
}
m, err := newMilkDropWindow(800, 600, presets)
m, err := newMilkDropWindow(800, 600, args)
if err != nil {
log.Fatal(err)
}
@ -175,6 +169,7 @@ var rootCmd = &cobra.Command{
It uses Milkdrop preset files to generate visualizations from standard input.`,
Run: milkbucket,
Args: validatePresets,
}
// Execute adds all child commands to the root command and sets flags appropriately.
@ -194,6 +189,4 @@ func init() {
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolVarP(&transition, "transition", "t", false, "smoothly transition between presets")
rootCmd.Flags().StringArrayVarP(&presets, "presets", "p", []string{}, "preset files to use")
}