move subcommands to new parser
This commit is contained in:
parent
d3319adb59
commit
a3f536c248
20 changed files with 307 additions and 395 deletions
|
@ -1,49 +1,50 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Sln.Internal;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
using Microsoft.DotNet.Tools.Sln;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Sln.Add
|
||||
{
|
||||
internal class AddProjectToSolutionCommand : DotNetSubCommandBase
|
||||
internal class AddProjectToSolutionCommand : CommandBase
|
||||
{
|
||||
public static DotNetSubCommandBase Create()
|
||||
private readonly AppliedOption _appliedCommand;
|
||||
private readonly string _fileOrDirectory;
|
||||
|
||||
public AddProjectToSolutionCommand(AppliedOption appliedCommand)
|
||||
{
|
||||
var command = new AddProjectToSolutionCommand()
|
||||
if (appliedCommand == null)
|
||||
{
|
||||
Name = "add",
|
||||
FullName = LocalizableStrings.AddAppFullName,
|
||||
Description = LocalizableStrings.AddSubcommandHelpText,
|
||||
HandleRemainingArguments = true,
|
||||
ArgumentSeparatorHelpText = LocalizableStrings.AddSubcommandHelpText,
|
||||
};
|
||||
throw new ArgumentNullException(nameof(appliedCommand));
|
||||
}
|
||||
_appliedCommand = appliedCommand;
|
||||
|
||||
command.HelpOption("-h|--help");
|
||||
|
||||
return command;
|
||||
_fileOrDirectory = appliedCommand.Arguments.Single();
|
||||
}
|
||||
|
||||
public override int Run(string fileOrDirectory)
|
||||
public override int Execute()
|
||||
{
|
||||
SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory);
|
||||
SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);
|
||||
|
||||
if (RemainingArguments.Count == 0)
|
||||
if (_appliedCommand.Arguments.Count == 0)
|
||||
{
|
||||
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd);
|
||||
}
|
||||
|
||||
PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ProjectDoesNotExist);
|
||||
var fullProjectPaths = RemainingArguments.Select((p) => Path.GetFullPath(p)).ToList();
|
||||
PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ProjectDoesNotExist);
|
||||
|
||||
var fullProjectPaths = _appliedCommand.Arguments
|
||||
.Select(Path.GetFullPath)
|
||||
.ToList();
|
||||
|
||||
var preAddProjectCount = slnFile.Projects.Count;
|
||||
|
||||
int preAddProjectCount = slnFile.Projects.Count;
|
||||
foreach (var fullProjectPath in fullProjectPaths)
|
||||
{
|
||||
slnFile.AddProject(fullProjectPath);
|
||||
|
@ -57,4 +58,4 @@ namespace Microsoft.DotNet.Tools.Sln.Add
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue