Skip to content

Commit

Permalink
tweak CLI handling to show errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riley committed May 24, 2022
1 parent 8ab1a9b commit f2f7e90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text.Json;
using CommandLine;
using CommandLine.Text;
using Ovation.FasterQC.Net.Modules;
using Ovation.FasterQC.Net.Readers;
using Ovation.FasterQC.Net.Utils;
Expand Down Expand Up @@ -31,12 +32,22 @@ private static void Main(string[] args)
}
);

_ = parser.ParseArguments<CliOptions>(args)
var parserResult = parser.ParseArguments<CliOptions>(args);
parserResult
.WithParsed(o =>
{
Settings = o;
new Program().Run();
});
})
.WithNotParsed(x =>
{
var helpText = HelpText.AutoBuild(parserResult, h =>
{
h.AutoVersion = false; // hides --version
return HelpText.DefaultParsingErrorsHandler(parserResult, h);
}, e => e);
Console.Error.WriteLine(helpText);
});
}

private void Run()
Expand Down
2 changes: 1 addition & 1 deletion Utils/CliOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CliOptions
[Option('f', "format", Required = true, HelpText = "Type of input file.")]
public ReaderType Format { get; set; }

[Option('m', "modules", Required = false, HelpText = "Space-separated list of modules to run, or 'all'.")]
[Option('m', "modules", Required = false, Default = new string[] { "all" }, HelpText = "Space-separated list of modules to run, or 'all'.")]
public IEnumerable<string> ModuleNames { get; set; } = Array.Empty<string>();

[Option('l', "read-limit", Required = false, HelpText = "Limit the number of reads processed")]
Expand Down

0 comments on commit f2f7e90

Please sign in to comment.