@@ -48,14 +48,14 @@ impl clap::builder::TypedValueParser for ThemeValueParser {
4848#[ clap( author, version, about, long_about = None ) ]
4949struct Cli {
5050 /// asciicast path/filename or URL
51- input_filename_or_url : String ,
51+ #[ clap( value_name = "INPUT_FILENAME_OR_URL" ) ]
52+ input : String ,
5253
53- /// GIF path/filename (output directory if outputting frames)
54- output_filename : String ,
55-
56- /// Output each frame as PNG image
57- #[ clap( long) ]
58- output_frames : bool ,
54+ /// GIF path/filename
55+ ///
56+ /// If path ends with a slash or is a directory frames are saved instead
57+ #[ clap( value_name = "OUTPUT_FILENAME_OR_DIR" ) ]
58+ output : String ,
5959
6060 /// Select frame rendering backend
6161 #[ clap( long, arg_enum, default_value_t = agg:: Renderer :: default ( ) ) ]
@@ -176,6 +176,10 @@ fn main() -> Result<()> {
176176 . format_timestamp ( None )
177177 . init ( ) ;
178178
179+ // output frames if path ends with a path separator or is a directory
180+ let output_frames = cli. output . ends_with ( std:: path:: MAIN_SEPARATOR_STR )
181+ || std:: fs:: metadata ( & cli. output ) . is_ok_and ( |x| x. is_dir ( ) ) ;
182+
179183 let config = agg:: Config {
180184 cols : cli. cols ,
181185 font_dirs : cli. font_dir ,
@@ -191,17 +195,17 @@ fn main() -> Result<()> {
191195 speed : cli. speed ,
192196 theme : cli. theme . map ( |theme| theme. 0 ) ,
193197 show_progress_bar : !cli. quiet ,
194- output_frames : cli . output_frames ,
195- output_filename : cli. output_filename . clone ( ) ,
198+ output_frames : output_frames,
199+ output_filename : cli. output . clone ( ) ,
196200 } ;
197201
198- let input = BufReader :: new ( reader ( & cli. input_filename_or_url ) ?) ;
202+ let input = BufReader :: new ( reader ( & cli. input ) ?) ;
199203 match agg:: run ( input, config) {
200204 Ok ( ok) => Ok ( ok) ,
201205 Err ( err) => {
202206 // do not try to delete a directory
203- if !cli . output_frames {
204- std:: fs:: remove_file ( & cli. output_filename ) ?;
207+ if !output_frames {
208+ std:: fs:: remove_file ( & cli. output ) ?;
205209 }
206210
207211 Err ( err)
0 commit comments