Skip to content

Commit

Permalink
Add experimental flag to bypass arg validation (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanis authored Mar 27, 2023
1 parent 8fc1bf1 commit 90515cb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/ActionsImporter/Commands/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public static class Common
IsRequired = false,
};

public static readonly Option<bool> Experimental = new("--experimental")
{
Description = "Enable experimental and unsupported features.",
IsRequired = false,
IsHidden = true
};

public static Command AppendTransformerOptions(this Command command)
{
ArgumentNullException.ThrowIfNull(command);
Expand Down Expand Up @@ -120,6 +127,8 @@ public static Command AppendGeneralOptions(this Command command)
}
);

command.AddGlobalOption(Experimental);

command.AddGlobalOption(Prerelease);

return command;
Expand Down
23 changes: 23 additions & 0 deletions src/ActionsImporter/Models/ParserExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.CommandLine.Parsing;
using ActionsImporter.Commands;

namespace ActionsImporter.Models;

public static class ParserExtensions
{
public static async Task<int> InvokeAsync(this Parser? parser, App? app, string[] args, bool experimental)
{
ArgumentNullException.ThrowIfNull(parser);
ArgumentNullException.ThrowIfNull(app);

if (experimental)
{
Console.WriteLine("Experimental features are enabled. Use at your own risk.");

await app.ExecuteActionsImporterAsync(args.Where(arg => !arg.Contains(Common.Experimental.Name, StringComparison.Ordinal)).ToArray());
return 0;
}

return await parser.InvokeAsync(args);
}
}
8 changes: 5 additions & 3 deletions src/ActionsImporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.CommandLine.Parsing;
using ActionsImporter;
using ActionsImporter.Commands;
using ActionsImporter.Models;
using ActionsImporter.Services;
using Version = ActionsImporter.Commands.Version;

Expand Down Expand Up @@ -47,16 +48,17 @@
.CancelOnProcessTermination()
.Build();


app.IsPrerelease = parser.Parse(args).HasOption(Common.Prerelease);
var parsedArguments = parser.Parse(args);
app.IsPrerelease = parsedArguments.HasOption(Common.Prerelease);

try
{
if (!Array.Exists(args, x => x == "update"))
{
await app.CheckForUpdatesAsync();
}
await parser.InvokeAsync(args);

await parser.InvokeAsync(app, args, parsedArguments.HasOption(Common.Experimental));
return 0;
}
catch (Exception e)
Expand Down

0 comments on commit 90515cb

Please sign in to comment.