text fixes for dotnet remove

This commit is contained in:
Jon Sequeira 2017-03-15 13:59:39 -07:00
parent bcfc16000c
commit 8a2be57617
4 changed files with 55 additions and 32 deletions

View file

@ -55,13 +55,15 @@ namespace Microsoft.DotNet.Cli
.ForwardAs(o => $"--package-directory {o.Arguments.Single()}"))),
Create.Command(
"reference",
"Command to add project to project reference",
Accept.OneOrMoreArguments(),
Tools.Add.ProjectToProjectReference.LocalizableStrings.AppFullName,
Accept.OneOrMoreArguments()
.With(name: "args",
description: Tools.Add.ProjectToProjectReference.LocalizableStrings.AppHelpText),
CommonOptions.HelpOption(),
Create.Option("-f|--framework",
"Add reference only when targeting a specific framework",
Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)
.With(name: "FRAMEWORK"))),
.With(name: "FRAMEWORK"))),
CommonOptions.HelpOption());
public static IEnumerable<string> QueryNuGet(string match)

View file

@ -11,9 +11,16 @@ namespace Microsoft.DotNet.Cli
{
DebugHelper.HandleDebugSwitch(ref args);
var result =
Parser.Instance.Parse(
ParseResult result;
try
{
result = Parser.Instance.Parse(
args.Single());
}
catch (Exception e)
{
throw new InvalidOperationException("The parser threw an exception.", e);
}
Console.WriteLine(result.Diagram());

View file

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
using static System.Array;
namespace Microsoft.DotNet.Cli
{
@ -10,33 +13,46 @@ namespace Microsoft.DotNet.Cli
{
public static IEnumerable<string> TargetFrameworksFromProjectFile()
{
var msbuildProj = MsbuildProject.FromFileOrDirectory(
new ProjectCollection(),
Directory.GetCurrentDirectory());
var msBuildProject = GetMSBuildProject();
foreach (var tfm in msbuildProj.GetTargetFrameworks())
if (msBuildProject == null)
{
yield break;
}
foreach (var tfm in msBuildProject.GetTargetFrameworks())
{
yield return tfm.GetShortFolderName();
}
}
public static IEnumerable<string> RunTimesFromProjectFile()
private static void Report(Exception e) =>
Reporter.Verbose.WriteLine($"Exception occurred while getting suggestions: {e}");
public static IEnumerable<string> RunTimesFromProjectFile() =>
GetMSBuildProject()
.GetRuntimeIdentifiers() ??
Empty<string>();
public static IEnumerable<string> ProjectReferencesFromProjectFile() =>
GetMSBuildProject()
?.GetProjectToProjectReferences()
.Select(r => r.Include) ??
Empty<string>();
private static MsbuildProject GetMSBuildProject()
{
var msbuildProj = MsbuildProject.FromFileOrDirectory(
new ProjectCollection(),
Directory.GetCurrentDirectory());
return msbuildProj.GetRuntimeIdentifiers();
}
public static IEnumerable<string> ProjectReferencesFromProjectFile()
{
var msbuildProj = MsbuildProject.FromFileOrDirectory(
new ProjectCollection(),
Directory.GetCurrentDirectory());
return msbuildProj.GetProjectToProjectReferences()
.Select(r => r.Include);
try
{
return MsbuildProject.FromFileOrDirectory(
new ProjectCollection(),
Directory.GetCurrentDirectory());
}
catch (Exception e)
{
Report(e);
return null;
}
}
}
}

View file

@ -16,17 +16,15 @@ namespace Microsoft.DotNet.Cli.Add.Reference.Tests
{
private const string HelpText = @".NET Add Project to Project reference Command
Usage: dotnet add <PROJECT> reference [options] [args]
Usage: dotnet add <PROJECT> reference [options] <args>
Arguments:
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one.
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one.
<args> Project to project references to add
Options:
-h|--help Show help information
-f|--framework <FRAMEWORK> Add reference only when targeting a specific framework
Additional Arguments:
Project to project references to add
-h, --help Show help information
-f, --framework <FRAMEWORK> Add reference only when targeting a specific framework
";
const string FrameworkNet451Arg = "-f net451";