1313#![ allow( clippy:: needless_update) ]
1414
1515use std:: fs:: File ;
16- use std:: path:: Path ;
16+ use std:: path:: { Path , PathBuf } ;
1717use std:: process:: { Command , Stdio } ;
1818
1919use symphonia:: core:: audio:: GenericAudioBufferRef ;
@@ -25,7 +25,7 @@ use symphonia::core::formats::{FormatOptions, FormatReader, TrackType};
2525use symphonia:: core:: io:: { MediaSourceStream , ReadOnlySource } ;
2626use symphonia:: core:: meta:: MetadataOptions ;
2727
28- use clap:: Arg ;
28+ use clap:: { Arg , ArgAction } ;
2929use log:: warn;
3030
3131/// The absolute maximum allowable sample delta. Around 2^-17 (-102.4dB).
@@ -66,7 +66,7 @@ struct TestResult {
6666 ref_unchecked_samples : u64 ,
6767}
6868
69- fn build_ffmpeg_command ( path : & str , gapless : bool ) -> Command {
69+ fn build_ffmpeg_command ( path : & Path , gapless : bool ) -> Command {
7070 let mut cmd = Command :: new ( "ffmpeg" ) ;
7171
7272 // Gapless argument must come before everything else.
@@ -91,15 +91,15 @@ fn build_ffmpeg_command(path: &str, gapless: bool) -> Command {
9191 cmd
9292}
9393
94- fn build_flac_command ( path : & str ) -> Command {
94+ fn build_flac_command ( path : & Path ) -> Command {
9595 let mut cmd = Command :: new ( "flac" ) ;
9696
9797 cmd. arg ( "--stdout" ) . arg ( "-d" ) . arg ( path) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: null ( ) ) ;
9898
9999 cmd
100100}
101101
102- fn build_mpg123_command ( path : & str , gapless : bool ) -> Command {
102+ fn build_mpg123_command ( path : & Path , gapless : bool ) -> Command {
103103 let mut cmd = Command :: new ( "mpg123" ) ;
104104
105105 if !gapless {
@@ -111,7 +111,7 @@ fn build_mpg123_command(path: &str, gapless: bool) -> Command {
111111 cmd
112112}
113113
114- fn build_oggdec_command ( path : & str ) -> Command {
114+ fn build_oggdec_command ( path : & Path ) -> Command {
115115 let mut cmd = Command :: new ( "oggdec" ) ;
116116 cmd. arg ( path) . arg ( "-o" ) . arg ( "-" ) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: null ( ) ) ;
117117 cmd
@@ -122,7 +122,7 @@ struct RefProcess {
122122}
123123
124124impl RefProcess {
125- fn try_spawn ( decoder : RefDecoder , gapless : bool , path : & str ) -> Result < RefProcess > {
125+ fn try_spawn ( decoder : RefDecoder , gapless : bool , path : & Path ) -> Result < RefProcess > {
126126 let mut cmd = match decoder {
127127 RefDecoder :: Ffmpeg => build_ffmpeg_command ( path, gapless) ,
128128 RefDecoder :: Flac => build_flac_command ( path) ,
@@ -343,7 +343,7 @@ fn run_check(
343343 Ok ( ( ) )
344344}
345345
346- fn run_test ( path : & str , opts : & TestOptions , result : & mut TestResult ) -> Result < ( ) > {
346+ fn run_test ( path : & Path , opts : & TestOptions , result : & mut TestResult ) -> Result < ( ) > {
347347 // 1. Start the reference decoder process.
348348 let mut ref_process = RefProcess :: try_spawn ( opts. ref_decoder , opts. gapless , path) ?;
349349
@@ -354,7 +354,7 @@ fn run_test(path: &str, opts: &TestOptions, result: &mut TestResult) -> Result<(
354354 let mut ref_inst = DecoderInstance :: try_open ( ref_mss, Default :: default ( ) , Default :: default ( ) ) ?;
355355
356356 // 3. Instantiate a Symphonia decoder for the test target.
357- let tgt_ms = Box :: new ( File :: open ( Path :: new ( path) ) ?) ;
357+ let tgt_ms = Box :: new ( File :: open ( path) ?) ;
358358 let tgt_mss = MediaSourceStream :: new ( tgt_ms, Default :: default ( ) ) ;
359359
360360 let tgt_fmt_opts = Default :: default ( ) ;
@@ -373,34 +373,57 @@ fn main() {
373373 . version ( "1.0" )
374374 . author ( "Philip Deljanov <philip.deljanov@gmail.com>" )
375375 . about ( "Check Symphonia output with a reference decoding" )
376- . arg ( Arg :: new ( "samples" ) . long ( "samples" ) . help ( "Print failures per sample" ) )
376+ . arg (
377+ Arg :: new ( "samples" )
378+ . long ( "samples" )
379+ . action ( ArgAction :: SetTrue )
380+ . help ( "Print failures per sample" ) ,
381+ )
377382 . arg (
378383 Arg :: new ( "stop-after-fail" )
379384 . long ( "first-fail" )
380385 . short ( 'f' )
386+ . action ( ArgAction :: SetTrue )
381387 . help ( "Stop testing after the first failed packet" ) ,
382388 )
383- . arg ( Arg :: new ( "quiet" ) . long ( "quiet" ) . short ( 'q' ) . help ( "Only print test results" ) )
389+ . arg (
390+ Arg :: new ( "quiet" )
391+ . long ( "quiet" )
392+ . short ( 'q' )
393+ . action ( ArgAction :: SetTrue )
394+ . help ( "Only print test results" ) ,
395+ )
384396 . arg (
385397 Arg :: new ( "keep-going" )
386398 . long ( "keep-going" )
399+ . action ( ArgAction :: SetTrue )
387400 . help ( "Continue after a decode error (may cause many failures)" ) ,
388401 )
389402 . arg (
390403 Arg :: new ( "decoder" )
391404 . long ( "ref" )
392- . takes_value ( true )
393- . possible_values ( [ "ffmpeg" , "flac" , "mpg123" , "oggdec" ] )
405+ . value_parser ( [ "ffmpeg" , "flac" , "mpg123" , "oggdec" ] )
394406 . default_value ( "ffmpeg" )
395407 . help ( "Specify a particular decoder to be used as the reference" ) ,
396408 )
397- . arg ( Arg :: new ( "no-gapless" ) . long ( "no-gapless" ) . help ( "Disable gapless decoding" ) )
398- . arg ( Arg :: new ( "INPUT" ) . help ( "The input file path" ) . required ( true ) . index ( 1 ) )
409+ . arg (
410+ Arg :: new ( "no-gapless" )
411+ . long ( "no-gapless" )
412+ . action ( ArgAction :: SetTrue )
413+ . help ( "Disable gapless decoding" ) ,
414+ )
415+ . arg (
416+ Arg :: new ( "INPUT" )
417+ . help ( "The input file path" )
418+ . value_parser ( clap:: value_parser!( PathBuf ) )
419+ . required ( true )
420+ . index ( 1 ) ,
421+ )
399422 . get_matches ( ) ;
400423
401- let path = matches. value_of ( "INPUT" ) . unwrap ( ) ;
424+ let path = matches. get_one :: < PathBuf > ( "INPUT" ) . expect ( "path is a required argument" ) ;
402425
403- let ref_decoder = match matches. value_of ( "decoder" ) . unwrap ( ) {
426+ let ref_decoder = match matches. get_one ( "decoder" ) . copied ( ) . unwrap ( ) {
404427 "ffmpeg" => RefDecoder :: Ffmpeg ,
405428 "flac" => RefDecoder :: Flac ,
406429 "mpg123" => RefDecoder :: Mpg123 ,
@@ -414,17 +437,17 @@ fn main() {
414437
415438 let opts = TestOptions {
416439 ref_decoder,
417- is_per_sample : matches. is_present ( "samples" ) ,
418- is_quiet : matches. is_present ( "quiet" ) ,
419- stop_after_fail : matches. is_present ( "stop-after-fail" ) ,
420- keep_going : matches. is_present ( "keep-going" ) ,
421- gapless : !matches. is_present ( "no-gapless" ) ,
440+ is_per_sample : matches. get_flag ( "samples" ) ,
441+ is_quiet : matches. get_flag ( "quiet" ) ,
442+ stop_after_fail : matches. get_flag ( "stop-after-fail" ) ,
443+ keep_going : matches. get_flag ( "keep-going" ) ,
444+ gapless : !matches. get_flag ( "no-gapless" ) ,
422445 ..Default :: default ( )
423446 } ;
424447
425448 let mut res: TestResult = Default :: default ( ) ;
426449
427- println ! ( "Input Path: {path}" ) ;
450+ println ! ( "Input Path: {}" , path . to_string_lossy ( ) ) ;
428451 println ! ( ) ;
429452
430453 if let Err ( err) = run_test ( path, & opts, & mut res) {
0 commit comments