Refactoring #3
+27
-1
@@ -34,6 +34,11 @@ const (
|
||||
placeholderStride uint32 = 4
|
||||
)
|
||||
|
||||
const (
|
||||
initialRetryDelay = 500 * time.Millisecond
|
||||
maxRetryDelay = 5 * time.Second
|
||||
)
|
||||
|
||||
type appArgs struct {
|
||||
ShowHelp bool
|
||||
Domain string
|
||||
@@ -53,7 +58,7 @@ type appArgs struct {
|
||||
|
||||
func printCliHelp(fs *pflag.FlagSet) {
|
||||
fmt.Printf("%s %s\n", APP_NAME, APP_VER)
|
||||
fmt.Println("Usage: mxl-player -d <domain> (-v <uuid> | -a <uuid>) [-f] [-h]")
|
||||
fmt.Println("Usage: mxl-player -d <domain> (-v <uuid> | -a <uuid>) [--max-attempts <count>] [-f] [-h]")
|
||||
fmt.Println(" [-g <gpu-id>] [-p <playback-id>] [--verbose]")
|
||||
fmt.Println(" or: mxl-player [--list-playback] [--list-gpu]")
|
||||
fmt.Println(" or: mxl-player (and set everything in GUI)")
|
||||
@@ -94,11 +99,18 @@ func main() {
|
||||
// f1 audio: 5fbec3b1-1b0f-417d-9059-8b94a47197eb
|
||||
var args appArgs
|
||||
flagSet := pflag.NewFlagSet(APP_NAME, pflag.ContinueOnError)
|
||||
flagSet.SortFlags = false
|
||||
flagSet.Usage = func() { printUsage(os.Stderr) }
|
||||
flagSet.BoolVarP(&args.ShowHelp, "help", "h", false, "Show help message and exit")
|
||||
flagSet.StringVarP(&args.Domain, "domain", "d", "", "MXL domain directory")
|
||||
flagSet.StringVarP(&args.VideoFlowId, "video", "v", "", "Video flow UUID")
|
||||
flagSet.StringVarP(&args.AudioFlowId, "audio", "a", "", "Audio flow UUID")
|
||||
flagSet.IntVar(
|
||||
&args.MaxAttempts,
|
||||
"max-attempts",
|
||||
0,
|
||||
"Maximum connection attempts per playback lifecycle; 0 retries indefinitely",
|
||||
)
|
||||
flagSet.BoolVarP(&args.IsFullscreen, "fullscreen", "f", false, "Run app in fullscreen mode")
|
||||
flagSet.Uint32VarP(&args.GpuId, "gpu-id", "g", 0, "GPU id [TODO]")
|
||||
flagSet.Uint32VarP(&args.PlaybackId, "playback-id", "p", 0, "Playback audio device id")
|
||||
@@ -115,6 +127,20 @@ func main() {
|
||||
printCliHelp(flagSet)
|
||||
return
|
||||
}
|
||||
if args.MaxAttempts < 0 {
|
||||
fmt.Fprintln(os.Stderr, "--max-attempts cannot be negative")
|
||||
printUsage(os.Stderr)
|
||||
os.Exit(2)
|
||||
}
|
||||
retryPolicy := playback.RetryPolicy{
|
||||
MaxAttempts: args.MaxAttempts,
|
||||
InitialDelay: initialRetryDelay,
|
||||
MaxDelay: maxRetryDelay,
|
||||
}
|
||||
if err := retryPolicy.Validate(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "invalid retry configuration:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if !args.ListAudio && !args.ListGPU {
|
||||
checkMXLargs(args)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user