dotnet-installer/src/dotnet/commands/dotnet-complete/ParseCommand.cs

54 lines
1.6 KiB
C#
Raw Normal View History

using System;
2017-03-09 10:53:17 -08:00
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Cli
{
public class ParseCommand
{
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
2017-03-15 13:59:39 -07:00
ParseResult result;
try
{
result = Parser.Instance.Parse(
2017-03-09 10:53:17 -08:00
args.Single());
2017-03-15 13:59:39 -07:00
}
catch (Exception e)
{
throw new InvalidOperationException("The parser threw an exception.", e);
}
2017-03-09 10:53:17 -08:00
Console.WriteLine(result.Diagram());
2017-04-14 10:27:24 -07:00
if (result.UnparsedTokens.Any())
{
Console.WriteLine("Unparsed Tokens: ");
2017-04-14 10:27:24 -07:00
Console.WriteLine(string.Join(" ", result.UnparsedTokens));
}
var optionValuesToBeForwarded = result.AppliedCommand()
.OptionValuesToBeForwarded();
if (optionValuesToBeForwarded.Any())
{
Console.WriteLine("Option values to be forwarded: ");
Console.WriteLine(string.Join(" ", optionValuesToBeForwarded));
}
if (result.Errors.Any())
{
Console.WriteLine();
Console.WriteLine("ERRORS");
Console.WriteLine();
foreach (var error in result.Errors)
{
2017-03-22 13:51:32 -07:00
Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error?.Message}");
}
}
2017-03-09 10:53:17 -08:00
return 0;
}
}
}