Skip to content

Commit cafc038

Browse files
authored
Merge pull request #359 from nblumhardt/multiple-i-args
Allow the `-i <FILENAME>` argument to be specified multiple times
2 parents c3421e5 + fa7c50b commit cafc038

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

src/SeqCli/Cli/Commands/IngestCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class IngestCommand : Command
4747
public IngestCommand(SeqConnectionFactory connectionFactory)
4848
{
4949
_connectionFactory = connectionFactory;
50-
_fileInputFeature = Enable(new FileInputFeature("File(s) to ingest", supportsWildcard: true));
50+
_fileInputFeature = Enable(new FileInputFeature("File(s) to ingest", allowMultiple: true));
5151
_invalidDataHandlingFeature = Enable<InvalidDataHandlingFeature>();
5252
_properties = Enable<PropertiesFeature>();
5353

src/SeqCli/Cli/Commands/PrintCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public PrintCommand(SeqCliOutputConfig outputConfig)
4444
_noColor = outputConfig.DisableColor;
4545
_forceColor = outputConfig.ForceColor;
4646

47-
_fileInputFeature = Enable(new FileInputFeature("CLEF file to read", supportsWildcard: true));
47+
_fileInputFeature = Enable(new FileInputFeature("CLEF file to read", allowMultiple: true));
4848

4949
Options.Add("f=|filter=",
5050
"Filter expression to select a subset of events",

src/SeqCli/Cli/Commands/Signal/ImportCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override async Task<int> Run()
5959
{
6060
var connection = _connectionFactory.Connect(_connection);
6161

62-
using var input = _fileInputFeature.OpenInput();
62+
using var input = _fileInputFeature.OpenSingleInput();
6363
var line = await input.ReadLineAsync();
6464
while (line != null)
6565
{

src/SeqCli/Cli/Features/FileInputFeature.cs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.IO;
18+
using System.Linq;
1819
using SeqCli.Util;
1920

2021
namespace SeqCli.Cli.Features;
2122

2223
class 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

Comments
 (0)