Skip to content

Commit

Permalink
loader: allow extra args by -- token
Browse files Browse the repository at this point in the history
  • Loading branch information
luantranminh committed Aug 8, 2024
1 parent 15bc213 commit 8d7ab47
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 51 deletions.
110 changes: 60 additions & 50 deletions src/Atlas.Provider.Loader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,68 @@ static int Main(string[] args)
string? framework = null;
string? context = null;
bool noBuild = false;
var positionalArgs = new List<string>();
var extraArgs = new List<string>();
bool parsingExtraArgs = false;

for (int i = 0; i < args.Length; i++)
{
switch (args[i])
if (args[i] == "--")
{
case "--project":
if (i + 1 < args.Length)
{
project = args[++i];
}
else
{
Console.WriteLine("Error: --project option requires a value.");
}
break;
case "--startup-project":
if (i + 1 < args.Length)
{
startupProject = args[++i];
}
else
{
Console.WriteLine("Error: --startup-project option requires a value.");
}
break;
case "--framework":
if (i + 1 < args.Length)
{
framework = args[++i];
}
else
{
Console.WriteLine("Error: --framework option requires a value.");
}
break;
case "--context":
if (i + 1 < args.Length)
{
context = args[++i];
}
else
{
Console.WriteLine("Error: --context option requires a value.");
}
break;
case "--no-build":
noBuild = true;
break;
default:
positionalArgs.Add(args[i]);
break;
parsingExtraArgs = true;
continue;
}
if (parsingExtraArgs)
{
extraArgs.Add(args[i]);
}
else
{
switch (args[i])
{
case "--project":
if (i + 1 < args.Length)
{
project = args[++i];
}
else
{
Console.WriteLine("Error: --project option requires a value.");
}
break;
case "--startup-project":
if (i + 1 < args.Length)
{
startupProject = args[++i];
}
else
{
Console.WriteLine("Error: --startup-project option requires a value.");
}
break;
case "--framework":
if (i + 1 < args.Length)
{
framework = args[++i];
}
else
{
Console.WriteLine("Error: --framework option requires a value.");
}
break;
case "--context":
if (i + 1 < args.Length)
{
context = args[++i];
}
else
{
Console.WriteLine("Error: --context option requires a value.");
}
break;
case "--no-build":
noBuild = true;
break;
}
}
}

Expand Down Expand Up @@ -114,9 +124,9 @@ static int Main(string[] args)
}

var arguments = new List<string>();
if (args != null)
if (extraArgs != null)
{
arguments.AddRange(args);
arguments.AddRange(extraArgs);
}
arguments.AddRange([
"--root-namespace", _project.RootNamespace!,
Expand Down
2 changes: 1 addition & 1 deletion test/Atlas.Provider.Test/GenerateSchemaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Can_generate_script(string providerName, string expectedFile)
{
WorkingDirectory = Path.GetFullPath("../../../../../src/Atlas.Provider.Demo"),
FileName = "dotnet",
Arguments = $"exec {dllFileName} {providerName}",
Arguments = $"exec {dllFileName} -- {providerName}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Expand Down

0 comments on commit 8d7ab47

Please sign in to comment.