Repository navigation
Expand file tree
/
Copy pathGetProjectCommand.cs
More file actions
72 lines (63 loc) · 2.61 KB
/
Copy pathGetProjectCommand.cs
File metadata and controls
72 lines (63 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation;
using EnvDTE;
using NuGet.VisualStudio;
namespace NuGet.PowerShell.Commands
{
/// <summary>
/// This cmdlet returns the list of project names in the current solution,
/// which is used for tab expansion.
/// </summary>
[Cmdlet(VerbsCommon.Get, "Project", DefaultParameterSetName = ParameterSetByName)]
[OutputType(typeof(Project))]
public class GetProjectCommand : NuGetBaseCommand
{
private const string ParameterSetByName = "ByName";
private const string ParameterSetAllProjects = "AllProjects";
private readonly ISolutionManager _solutionManager;
public GetProjectCommand()
: this(ServiceLocator.GetInstance<ISolutionManager>(),
ServiceLocator.GetInstance<IHttpClientEvents>())
{
}
public GetProjectCommand(ISolutionManager solutionManager, IHttpClientEvents httpClientEvents)
: base(solutionManager, null, httpClientEvents)
{
_solutionManager = solutionManager;
}
[Parameter(Mandatory = false, Position = 0, ParameterSetName = ParameterSetByName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "PowerShell API requirement")]
public string[] Name { get; set; }
[Parameter(Mandatory = true, ParameterSetName = ParameterSetAllProjects)]
public SwitchParameter All { get; set; }
protected override void ProcessRecordCore()
{
if (!SolutionManager.IsSolutionOpen)
{
ErrorHandler.ThrowSolutionNotOpenTerminatingError();
}
if (All.IsPresent)
{
WriteObject(_solutionManager.GetProjects(), enumerateCollection: true);
}
else
{
// No name specified; return default project (if not null)
if (Name == null)
{
Project defaultProject = _solutionManager.DefaultProject;
if (defaultProject != null)
{
WriteObject(defaultProject);
}
}
else
{
// get all projects matching name(s) - handles wildcards
WriteObject(GetProjectsByName(Name), enumerateCollection: true);
}
}
}
}
}