Skip to content

Commit

Permalink
make module list available via --help
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljon committed May 18, 2022
1 parent 6f79480 commit d9562ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Modules/ModuleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class ModuleFactory
{
private static Dictionary<string, IQcModule>? moduleMap;

private static Dictionary<string, IQcModule> ModuleMap
public static Dictionary<string, IQcModule> ModuleMap
{
get
{
Expand Down
38 changes: 32 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
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 +33,36 @@ private static void Main(string[] args)
}
);

_ = parser.ParseArguments<CliOptions>(args)
.WithParsed(o =>
{
Settings = o;
new Program().Run();
});
var parserResult = parser.ParseArguments<CliOptions>(args);

parserResult.WithParsed(o =>
{
Settings = o;
new Program().Run();
})
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
}

static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
{
var moduleList = ModuleFactory.ModuleMap;
var sb = new StringBuilder("List of available modules:").AppendLine();

foreach (var module in moduleList)
{
sb.AppendLine($"\t{module.Key} -> {module.Value.Description}");
}

var helpText = HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false;
h.MaximumDisplayWidth = 120;
h.AddPostOptionsText(sb.ToString());

return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e);

Console.Error.WriteLine(helpText);
}

private void Run()
Expand Down

0 comments on commit d9562ce

Please sign in to comment.