Files
galahad2lcd/internal/cli/flags.go
T
Maksim Totmin 4c34f0bedc Initial commit: Go driver for the Lian Li Galahad II LCD
Streams H.264 to the Galahad II LCD via USB (gousb) with:
- ffmpeg CLI transcoding (no fragile FFmpeg C-ABI bindings)
- pure-Go Annex-B access-unit splitting
- framerate pacing with graceful shutdown and USB reconnect
- TOML config, cobra CLI, structured slog logging, unit tests
2026-08-19 12:03:54 +07:00

49 lines
1.2 KiB
Go

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
}