update CliCommandLine, other code changes
This commit is contained in:
parent
5c4db56d3b
commit
a6c2b6c9f6
11 changed files with 77 additions and 32 deletions
|
@ -287,7 +287,7 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasExtension(string filePath, string extension)
|
public static bool HasExtension(this string filePath, string extension)
|
||||||
{
|
{
|
||||||
var comparison = StringComparison.Ordinal;
|
var comparison = StringComparison.Ordinal;
|
||||||
|
|
||||||
|
@ -335,5 +335,8 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
notExisting.Select(p => string.Format(pathDoesNotExistLocalizedFormatString, p))));
|
notExisting.Select(p => string.Format(pathDoesNotExistLocalizedFormatString, p))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsDirectory(this string path) =>
|
||||||
|
File.GetAttributes(path).HasFlag(FileAttributes.Directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
|
@ -63,5 +64,25 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
||||||
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
||||||
|
|
||||||
|
public static ArgumentsRule ExistingSlnFileOrDirectoryOnly(
|
||||||
|
this ArgumentsRule rule) =>
|
||||||
|
rule
|
||||||
|
.ExistingFilesOnly()
|
||||||
|
.And(new ArgumentsRule(o =>
|
||||||
|
{
|
||||||
|
foreach (var path in o.Arguments)
|
||||||
|
{
|
||||||
|
if (path.HasExtension(".sln") ||
|
||||||
|
path.IsDirectory())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"Specified path '{path}' is not a directory or solution file.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
public static void ShowHelpIfRequested(this ParseResult parseResult)
|
public static void ShowHelpIfRequested(this ParseResult parseResult)
|
||||||
{
|
{
|
||||||
if (parseResult.AppliedOptions.Any(o => o.HasOption("help")))
|
if (parseResult.HasOption("help"))
|
||||||
{
|
{
|
||||||
// NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
|
// NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point.
|
||||||
throw new HelpException(parseResult.Command().HelpView());
|
throw new HelpException(parseResult.Command().HelpView());
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace Microsoft.DotNet.Cli
|
||||||
CompleteCommandParser.Complete(),
|
CompleteCommandParser.Complete(),
|
||||||
CommonOptions.HelpOption(),
|
CommonOptions.HelpOption(),
|
||||||
Create.Option("--info", ""),
|
Create.Option("--info", ""),
|
||||||
Create.Option("-d", "")));
|
Create.Option("-d", ""),
|
||||||
|
Create.Option("--debug", "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,18 +22,15 @@ namespace Microsoft.DotNet.Tools.Add
|
||||||
internal override Dictionary<string, Func<AppliedOption, CommandBase>> SubCommands =>
|
internal override Dictionary<string, Func<AppliedOption, CommandBase>> SubCommands =>
|
||||||
new Dictionary<string, Func<AppliedOption, CommandBase>>
|
new Dictionary<string, Func<AppliedOption, CommandBase>>
|
||||||
{
|
{
|
||||||
{
|
["reference"] =
|
||||||
"reference",
|
add => new AddProjectToProjectReferenceCommand(
|
||||||
add => new AddProjectToProjectReferenceCommand(
|
add["reference"],
|
||||||
add["reference"],
|
add.Value<string>()),
|
||||||
add.Value<string>())
|
|
||||||
},
|
["package"] =
|
||||||
{
|
add => new AddPackageReferenceCommand(
|
||||||
"package",
|
add["package"],
|
||||||
add => new AddPackageReferenceCommand(
|
add.Value<string>())
|
||||||
add["package"],
|
|
||||||
add.Value<string>())
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -20,17 +20,22 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
|
||||||
private readonly string _packageId;
|
private readonly string _packageId;
|
||||||
private readonly string _fileOrDirectory;
|
private readonly string _fileOrDirectory;
|
||||||
|
|
||||||
public AddPackageReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory)
|
public AddPackageReferenceCommand(
|
||||||
|
AppliedOption appliedCommand,
|
||||||
|
string fileOrDirectory)
|
||||||
{
|
{
|
||||||
|
if (appliedCommand == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(appliedCommand));
|
||||||
|
}
|
||||||
|
if (fileOrDirectory == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(fileOrDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
_appliedCommand = appliedCommand;
|
_appliedCommand = appliedCommand;
|
||||||
_fileOrDirectory = fileOrDirectory;
|
_fileOrDirectory = fileOrDirectory;
|
||||||
_packageId = appliedCommand.Value<string>();
|
_packageId = appliedCommand.Value<string>();
|
||||||
|
|
||||||
|
|
||||||
if ( string.IsNullOrWhiteSpace(_packageId) || _appliedCommand.Arguments.Count > 1)
|
|
||||||
{
|
|
||||||
throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Execute()
|
public override int Execute()
|
||||||
|
|
|
@ -20,12 +20,19 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
private readonly AppliedOption _appliedCommand;
|
private readonly AppliedOption _appliedCommand;
|
||||||
private readonly string _fileOrDirectory;
|
private readonly string _fileOrDirectory;
|
||||||
|
|
||||||
public AddProjectToProjectReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory)
|
public AddProjectToProjectReferenceCommand(
|
||||||
|
AppliedOption appliedCommand,
|
||||||
|
string fileOrDirectory)
|
||||||
{
|
{
|
||||||
if (appliedCommand == null)
|
if (appliedCommand == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(appliedCommand));
|
throw new ArgumentNullException(nameof(appliedCommand));
|
||||||
}
|
}
|
||||||
|
if (fileOrDirectory == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(fileOrDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
_appliedCommand = appliedCommand;
|
_appliedCommand = appliedCommand;
|
||||||
_fileOrDirectory = fileOrDirectory;
|
_fileOrDirectory = fileOrDirectory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,22 @@ namespace Microsoft.DotNet.Cli
|
||||||
{
|
{
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
var resultOfParsingArg =
|
var result =
|
||||||
Parser.Instance.Parse(
|
Parser.Instance.Parse(
|
||||||
args.Single());
|
args.Single());
|
||||||
|
|
||||||
Console.WriteLine(resultOfParsingArg.Diagram());
|
Console.WriteLine(result.Diagram());
|
||||||
|
|
||||||
|
if (result.Errors.Any())
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("ERRORS");
|
||||||
|
Console.WriteLine();
|
||||||
|
foreach (var error in result.Errors)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,19 @@ namespace Microsoft.DotNet.Cli
|
||||||
"sln",
|
"sln",
|
||||||
".NET modify solution file command",
|
".NET modify solution file command",
|
||||||
Accept.ExactlyOneArgument()
|
Accept.ExactlyOneArgument()
|
||||||
|
.ExistingSlnFileOrDirectoryOnly()
|
||||||
.DefaultToCurrentDirectory(),
|
.DefaultToCurrentDirectory(),
|
||||||
CommonOptions.HelpOption(),
|
CommonOptions.HelpOption(),
|
||||||
Create.Command("add",
|
Create.Command("add",
|
||||||
".NET Add project(s) to a solution file Command",
|
".NET Add project(s) to a solution file Command",
|
||||||
Accept.ExactlyOneArgument()
|
Accept.OneOrMoreArguments(),
|
||||||
.With(name: "SLN_FILE"),
|
|
||||||
CommonOptions.HelpOption()),
|
CommonOptions.HelpOption()),
|
||||||
Create.Command("list",
|
Create.Command("list",
|
||||||
"List all projects in the solution.",
|
"List all projects in the solution.",
|
||||||
Accept.ExactlyOneArgument()
|
Accept.OneOrMoreArguments(),
|
||||||
.With(name: "SLN_FILE"),
|
|
||||||
CommonOptions.HelpOption()),
|
CommonOptions.HelpOption()),
|
||||||
Create.Command("remove",
|
Create.Command("remove",
|
||||||
"Remove the specified project(s) from the solution. The project is not impacted."));
|
"Remove the specified project(s) from the solution. The project is not impacted.",
|
||||||
|
Accept.OneOrMoreArguments()));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,7 +40,7 @@
|
||||||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
|
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
|
||||||
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
|
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
||||||
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-88" />
|
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-92" />
|
||||||
<PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" />
|
<PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" />
|
||||||
<PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" />
|
<PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" />
|
||||||
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />
|
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />
|
||||||
|
|
|
@ -42,6 +42,6 @@
|
||||||
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
|
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
|
||||||
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
|
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
||||||
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-88" />
|
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-92" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Add table
Reference in a new issue