1515using System ;
1616using System . Collections . Generic ;
1717using System . IO ;
18+ using System . Linq ;
1819using SeqCli . Util ;
1920
2021namespace SeqCli . Cli . Features ;
2122
2223class FileInputFeature : CommandFeature
2324{
2425 readonly string _description ;
25- readonly bool _supportsWildcard ;
26+ readonly bool _allowMultiple ;
27+ readonly List < string > _inputFilenames = new ( ) ;
2628
27- public FileInputFeature ( string description , bool supportsWildcard = false )
29+ public FileInputFeature ( string description , bool allowMultiple = false )
2830 {
2931 _description = description ;
30- _supportsWildcard = supportsWildcard ;
32+ _allowMultiple = allowMultiple ;
3133 }
3234
33- string ? InputFilename { get ; set ; }
34-
3535 public override void Enable ( OptionSet options )
3636 {
37- var wildcardHelp = _supportsWildcard ? $ ", including the `{ DirectoryExt . Wildcard } ` wildcard" : "" ;
37+ var wildcardHelp = _allowMultiple ? $ ", including the `{ DirectoryExt . Wildcard } ` wildcard" : "" ;
3838 options . Add ( "i=|input=" ,
3939 $ "{ _description } { wildcardHelp } ; if not specified, `STDIN` will be used",
40- v => InputFilename = string . IsNullOrWhiteSpace ( v ) ? null : v . Trim ( ) ) ;
40+ v =>
41+ {
42+ if ( ! string . IsNullOrWhiteSpace ( v ) )
43+ {
44+ _inputFilenames . Add ( v . Trim ( ) ) ;
45+ }
46+ } ) ;
4147 }
4248
4349 static TextReader OpenText ( string filename )
@@ -46,21 +52,29 @@ static TextReader OpenText(string filename)
4652 File . Open ( filename , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ) ;
4753 }
4854
49- public TextReader OpenInput ( )
55+ public TextReader OpenSingleInput ( )
5056 {
51- return InputFilename != null ? OpenText ( InputFilename ) : Console . In ;
57+ return _inputFilenames . SingleOrDefault ( ) is { } filename ? OpenText ( filename ) : Console . In ;
5258 }
5359
5460 public IEnumerable < TextReader > OpenInputs ( )
5561 {
56- if ( InputFilename == null || ! DirectoryExt . IncludesWildcard ( InputFilename ) )
62+ if ( _inputFilenames . Count == 0 )
5763 {
58- yield return OpenInput ( ) ;
64+ yield return OpenSingleInput ( ) ;
5965 }
60- else
66+
67+ foreach ( var filename in _inputFilenames )
6168 {
62- foreach ( var path in DirectoryExt . GetFiles ( InputFilename ) )
63- yield return OpenText ( path ) ;
69+ if ( ! DirectoryExt . IncludesWildcard ( filename ) )
70+ {
71+ yield return OpenText ( filename ) ;
72+ }
73+ else
74+ {
75+ foreach ( var path in DirectoryExt . GetFiles ( filename ) )
76+ yield return OpenText ( path ) ;
77+ }
6478 }
6579 }
6680}
0 commit comments