remove command fixes

This commit is contained in:
Jon Sequeira 2017-03-15 09:27:27 -07:00
parent bbc2722cb7
commit c316b98c74
4 changed files with 33 additions and 10 deletions

View file

@ -21,8 +21,15 @@ namespace Microsoft.DotNet.Tools.Remove
internal override Dictionary<string, Func<AppliedOption, CommandBase>> SubCommands =>
new Dictionary<string, Func<AppliedOption, CommandBase>>
{
{ "reference", o => new RemoveProjectToProjectReferenceCommand(o) },
{ "package", o => new RemovePackageReferenceCommand(o) }
["reference"] =
remove => new RemoveProjectToProjectReferenceCommand(
remove["reference"],
remove.Value<string>()),
["package"] =
remove => new RemovePackageReferenceCommand(
remove["package"],
remove.Value<string>())
};
public static int Run(string[] args)

View file

@ -12,14 +12,17 @@ namespace Microsoft.DotNet.Cli
public static Command Remove() =>
Create.Command("remove",
".NET Remove Command",
Accept.ZeroOrOneArgument()
Accept.ExactlyOneArgument()
.ExistingFilesOnly()
.DefaultToCurrentDirectory()
.With(name: "PROJECT",
description: CommonLocalizableStrings.ArgumentsProjectDescription)
.DefaultToCurrentDirectory(),
CommonOptions.HelpOption(),
Create.Command("package",
LocalizableStrings.AppFullName,
CommonOptions.HelpOption()),
Create.Command(
"package",
LocalizableStrings.AppFullName,
CommonOptions.HelpOption()),
Create.Command(
"reference",
LocalizableStrings.AppFullName,

View file

@ -16,19 +16,25 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference
private readonly AppliedOption _appliedCommand;
private readonly string _fileOrDirectory;
public RemovePackageReferenceCommand(AppliedOption appliedCommand)
public RemovePackageReferenceCommand(
AppliedOption appliedCommand,
string fileOrDirectory)
{
if (appliedCommand == null)
{
throw new ArgumentNullException(nameof(appliedCommand));
}
if (fileOrDirectory == null)
{
throw new ArgumentNullException(nameof(fileOrDirectory));
}
if (_appliedCommand.Arguments.Count != 1)
{
throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference);
}
_appliedCommand = appliedCommand;
_fileOrDirectory = appliedCommand.Arguments.Single();
_fileOrDirectory = fileOrDirectory;
}
public override int Execute()

View file

@ -15,20 +15,27 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference
private readonly AppliedOption _appliedCommand;
private readonly string _fileOrDirectory;
public RemoveProjectToProjectReferenceCommand(AppliedOption appliedCommand)
public RemoveProjectToProjectReferenceCommand(
AppliedOption appliedCommand,
string fileOrDirectory)
{
if (appliedCommand == null)
{
throw new ArgumentNullException(nameof(appliedCommand));
}
if (fileOrDirectory == null)
{
throw new ArgumentNullException(nameof(fileOrDirectory));
}
if (appliedCommand.Arguments.Count == 0)
{
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
}
_appliedCommand = appliedCommand;
_fileOrDirectory = appliedCommand.Arguments.Single();
_fileOrDirectory = fileOrDirectory;
}
public override int Execute()