This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-toolbuilder-cil/src/MfGames.ToolBuilder/FakedRootCommand.cs
Dylan R. E. Moonfire 1f1d0a4d9f feat: provide the names via the tool builder
BREAKING CHANGE: Changed the API.
2021-11-30 20:12:20 -06:00

29 lines
853 B
C#

using System;
using System.CommandLine;
using System.Linq;
namespace MfGames.ToolBuilder
{
/// <summary>
/// Fakes the functionality of the RootCommand because of the given issue:
/// https://github.com/dotnet/command-line-api/issues/1471
/// In short, RootCommand doesn't resolve properly when working in certain
/// situations, mainly having the command line parser in a library that is
/// called by another executable.
/// </summary>
public class FakedRootCommand : Command
{
public FakedRootCommand(ToolNames names)
: base(names.GetExecutableName(), string.Empty)
{
}
public static string[] GetArguments()
{
string[] args = Environment.GetCommandLineArgs();
return args.Length == 0 ? args : args.Skip(1).ToArray();
}
}
}