package cli import ( "fmt" "os" "path/filepath" "github.com/spf13/cobra" "galahad2lcd/internal/config" ) // applyOverrides merges explicitly provided flags into cfg. Zero-valued // flags are ignored unless the user actually changed them. func applyOverrides(cmd *cobra.Command, cfg *config.Config, input string, rotate int, speed, fps float64) error { if cmd.Flags().Changed("input") { abs, err := resolveInput(input) if err != nil { return err } cfg.Display.Input = abs } if cmd.Flags().Changed("rotate") { cfg.Display.Rotate = rotate } if cmd.Flags().Changed("speed") { cfg.Display.Speed = speed } if cmd.Flags().Changed("fps") { cfg.Stream.FPS = fps } return nil } // resolveInput converts a relative path to an absolute one and verifies the // file exists, returning a helpful error otherwise. func resolveInput(input string) (string, error) { abs, err := filepath.Abs(input) if err != nil { return "", fmt.Errorf("resolve input %q: %w", input, err) } if st, err := os.Stat(abs); err != nil { return "", fmt.Errorf("input file %q does not exist", abs) } else if st.IsDir() { return "", fmt.Errorf("input %q is a directory, expected a media file", abs) } return abs, nil }