throw exceptions for command not found

This commit is contained in:
Jon Sequeira 2017-03-13 20:06:59 -07:00
parent ace4fe49f6
commit 2c96d8e8b9
4 changed files with 11 additions and 13 deletions

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
namespace Microsoft.DotNet.Cli
{
@ -29,14 +30,18 @@ namespace Microsoft.DotNet.Cli
var subcommandName = result.Command().Name;
try
{
var create = SubCommands[subcommandName];
var command = create(result["dotnet"][CommandName]);
try
{
return command.Execute();
}
catch (KeyNotFoundException e)
{
throw new GracefulException(CommonLocalizableStrings.RequiredCommandNotPassed);
}
catch (GracefulException e)
{
Reporter.Error.WriteLine(e.Message.Red());

View file

@ -9,15 +9,9 @@ namespace Microsoft.DotNet.Cli
[Obsolete("This is intended to facilitate refactoring during parser replacement and should not be used after that work is done.")]
public class HelpException : Exception
{
public HelpException(
string message,
bool isError = false) : base(message)
public HelpException(string message) : base(message)
{
IsError = isError;
Data.Add(ExceptionExtensions.CLI_User_Displayed_Exception, true);
}
public bool IsError { get; }
}
}

View file

@ -80,7 +80,7 @@ namespace Microsoft.DotNet.Cli
catch (HelpException e)
{
Reporter.Output.Write(e.Message);
return e.IsError ? 1 : 0;
return 0;
}
catch (Exception e) when (e.ShouldBeDisplayedAsError())
{

View file

@ -12,7 +12,6 @@ namespace Microsoft.DotNet.Cli
"sln",
".NET modify solution file command",
Accept.ExactlyOneArgument()
.ExistingSlnFileOrDirectoryOnly()
.DefaultToCurrentDirectory()
.With(name: "SLN_FILE"),
CommonOptions.HelpOption(),