Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OpenWrap.Commands/CommandDocumentation.resx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ Note that the NuPack support is only provided for backward compatibility with le
<data name="list-wrap" xml:space="preserve">
<value>Lists or queries all packages in a repository.</value>
</data>
<data name="list-wrap-detailed" xml:space="preserve">
<value>Displays package description if present.</value>
</data>
<data name="list-wrap-query" xml:space="preserve">
<value>Specifies the wildcard to be used when listing packages in a repository.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/OpenWrap.Commands/OpenWrap.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="Wrap\SetWrapCommand.cs" />
<Compile Include="Wrap\TestWrapCommand.cs" />
<Compile Include="Wrap\UpdatePackageVertex.cs" />
<Compile Include="Wrap\ViewWrapCommand.cs" />
<Compile Include="Wrap\WrapCommand.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 13 additions & 1 deletion src/OpenWrap.Commands/Wrap/ListWrapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using OpenWrap.Collections;
using OpenWrap.Commands.Remote;
using OpenWrap.Configuration;
using OpenWrap.PackageManagement;
using OpenWrap.PackageModel;
using OpenWrap.Repositories;
using OpenWrap.Runtime;
using OpenWrap.Services;
Expand All @@ -20,6 +22,9 @@ public class ListWrapCommand : WrapCommand
[CommandInput]
public bool System { get; set; }

[CommandInput(IsValueRequired = false)]
public bool Detailed { get; set; }

string _remote;
bool _remoteSet;

Expand All @@ -44,10 +49,17 @@ public override IEnumerable<ICommandOutput> Execute()
yield break;
}

foreach (var m in PackageManager.ListPackages(repoToList, Query))
var currentPackages = CurrentPackages();

foreach (var m in PackageManager.ListPackages(repoToList, Query, Detailed ? PackageListOptions.Detailed : PackageListOptions.Default, currentPackages))
yield return ToOutput(m);
}

IEnumerable<IPackageInfo> CurrentPackages()
{
return HostEnvironment.ProjectRepository != null ? HostEnvironment.ProjectRepository.PackagesByName.NotNull().SelectMany(x => x) : Enumerable.Empty<IPackageInfo>();
}

IEnumerable<IPackageRepository> GetRepositoryToList()
{
if (System)
Expand Down
72 changes: 72 additions & 0 deletions src/OpenWrap.Commands/Wrap/ViewWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenWrap.PackageManagement;
using OpenWrap.PackageModel;

namespace OpenWrap.Commands.Wrap
{
[Command(Noun = "wrap", Verb = "view")]
public class ViewWrapCommand : WrapCommand
{
bool? _project;

[CommandInput(IsRequired = true, Position = 0)]
public string Name { get; set; }

[CommandInput]
public Version Version { get; set; }

[CommandInput]
public bool System { get; set; }

[CommandInput]
public bool Project
{
get { return _project ?? !System; }
set { _project = value; }
}

public override IEnumerable<ICommandOutput> Execute()
{
return Either(VerifyInputs()).Or(ExecuteCore());
}

IEnumerable<ICommandOutput> ExecuteCore()
{
IPackageInfo item = null;

if ( System )
{
item = PackageInfo(HostEnvironment.SystemRepository.PackagesByName[Name]);
}
if (Project)
{
item = PackageInfo(HostEnvironment.ProjectRepository.PackagesByName[Name]);
}

if (item == null)
yield return new Error("No package found named {1}", Name);
else
yield return new ViewWrapCommandOutput(item);
}

IEnumerable<ICommandOutput> VerifyInputs()
{
if (System && !HostEnvironment.SystemRepository.PackagesByName[Name].Any())
yield return new Error("Cannot find package named '{0}' in system repository.", Name);
if (Project && HostEnvironment.ProjectRepository == null)
yield return new Error("Not in a package directory.");
if (Project && HostEnvironment.ProjectRepository != null && !HostEnvironment.ProjectRepository.PackagesByName[Name].Any())
yield return new Error("Cannot find package named '{0}' in project repository.", Name);
}

IPackageInfo PackageInfo(IEnumerable<IPackageInfo> packageInfos)
{
if (Version != null)
return packageInfos.OrderByDescending(x => x.Version).FirstOrDefault(x => x.Version.Major.Equals(Version.Major) && x.Version.Major.Equals(Version.Major));

return packageInfos.Last();
}
}
}
58 changes: 58 additions & 0 deletions src/OpenWrap.Tests/Commands/Wrap/listWrapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,63 @@ public void packages_are_found_in_any_remote()
.Check(x => x.ShouldHaveAtLeastOne(n => n.Name.Equals("ring-of-power")));
}
}
public class listing_packages_with_detailed_option : command_context<ListWrapCommand>
{
public listing_packages_with_detailed_option()
{
given_project_package("one-ring", "1.1", "desc 1.1");
given_project_package("sauron", "2.0");
given_dependency("depends: one-ring");
given_dependency("depends: sauron");

when_executing_command("one*", "-detailed");
}
[Test]
public void correct_description_is_returned()
{
Results.OfType<PackageFoundCommandOutput>()
.ShouldHaveCountOf(1)
.First().ToString().ShouldContain("desc 1.1");
}
}

public class listing_packages_will_hightlight_current : command_context<ListWrapCommand>
{
public listing_packages_will_hightlight_current()
{
given_project_package("one-ring", "1.0");
given_remote_package("one-ring", "1.0".ToVersion());
given_remote_package("one-ring", "1.1".ToVersion());
given_remote_package("one-ring-rules-them-all", "1.1".ToVersion());
given_project_package("sauron", "2.0");
given_dependency("depends: one-ring");
given_dependency("depends: sauron");

when_executing_command("*n*", "-remote");
}
[Test]
public void correct_version_is_highlighted()
{
var s = Results.OfType<PackageFoundCommandOutput>()
.ShouldHaveCountOf(2)
.First().ToString();
Console.WriteLine(s);
s.ShouldContain("current: 1.0");
}

[Test]
public void current_version_is_still_listed_as_available()
{
Results.OfType<PackageFoundCommandOutput>()
.ShouldHaveCountOf(2)
.First().ToString().ShouldContain("available: 1.0, 1.1");
}
[Test]
public void current_version_list_only_for_installed_package()
{
Results.OfType<PackageFoundCommandOutput>()
.ShouldHaveCountOf(2)
.ElementAt(1).ToString().ShouldNotContain("current: ");
}
}
}
76 changes: 76 additions & 0 deletions src/OpenWrap.Tests/Commands/Wrap/viewWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Linq;
using NUnit.Framework;
using OpenWrap.Commands.contexts;
using OpenWrap.Commands.Wrap;
using OpenWrap.PackageManagement;
using OpenWrap.Testing;

namespace viewWrap_specs
{
public class viewing_a_package : command_context<ViewWrapCommand>
{
public viewing_a_package()
{
given_project_package("one-ring", "1.0", string.Empty, "depends: sauron 2.0");
given_project_package("sauron", "2.0");

when_executing_command("one-ring");
}
[Test]
public void matching_package_is_returned()
{
var s = Results.OfType<ViewWrapCommandOutput>()
.ShouldHaveCountOf(1)
.First().ToString();
Console.WriteLine(s);
s.ShouldContain("name: one-ring");
}
[Test]
public void displays_dependencies()
{
Results.OfType<ViewWrapCommandOutput>()
.ShouldHaveCountOf(1)
.First().ToString().ShouldContain("dependencies: sauron 2.0");
}

}

public class viewing_a_package_version : command_context<ViewWrapCommand>
{
public viewing_a_package_version()
{
given_project_package("one-ring", "0.1.0");
given_project_package("one-ring", "0.1.1");
given_project_package("sauron", "2.0");

when_executing_command("one-ring", "-version", "0.1");
}
[Test]
public void matching_package_is_returned()
{
Results.OfType<ViewWrapCommandOutput>()
.ShouldHaveCountOf(1)
.First().ToString().ShouldContain("version: 0.1.1");
}
}

public class viewing_a_system_package : command_context<ViewWrapCommand>
{
public viewing_a_system_package()
{
given_project_package("one-ring", "1.0");
given_system_package("one-ring", "1.0");
given_system_package("one-ring", "2.0");

when_executing_command("one-ring", "-system");
}
[Test]
public void matching_package_is_returned()
{
Results.OfType<ViewWrapCommandOutput>()
.ShouldHaveCountOf(1)
.First().ToString().ShouldContain("version: 2.0");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class successful_add_triggers_dependent_removal : contexts.add_wrap_with_hooks
public successful_add_triggers_dependent_removal()
{
given_project_repository();
given_project_package("one-ring", "1.0.0", "depends: fire = 1.0");
given_project_package("one-ring", "1.0.0", string.Empty, "depends: fire = 1.0");
given_project_package("fire", "1.0");
given_dependency("depends: one-ring");

Expand Down
20 changes: 14 additions & 6 deletions src/OpenWrap.Tests/Commands/contexts/command_context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ protected void given_dependency(string dependency)
protected void given_project_package(string name, string version, params string[] dependencies)
{
given_project_repository(new InMemoryRepository("Project repository"));
AddPackage(Environment.ProjectRepository, name, version, dependencies);
AddPackage(Environment.ProjectRepository, name, version, dependencies, string.Empty);
}

protected void given_project_package(string name, string version, string description, params string[] dependencies)
{
given_project_repository(new InMemoryRepository("Project repository"));
AddPackage(Environment.ProjectRepository, name, version, dependencies, description);
}

protected void given_project_repository()
Expand All @@ -99,20 +105,21 @@ protected void given_current_directory_repository(CurrentDirectoryRepository rep
protected void given_remote_package(string name, Version version, params string[] dependencies)
{
// note Version is a version type because of overload resolution...
AddPackage(Environment.RemoteRepository, name, version.ToString(), dependencies);
AddPackage(Environment.RemoteRepository, name, version.ToString(), dependencies, string.Empty);
}

protected void given_remote_package(string repositoryName, string name, Version version, params string[] dependencies)
{
AddPackage(Environment.RemoteRepositories.First(x=>x.Name == repositoryName), name, version.ToString(), dependencies);
AddPackage(Environment.RemoteRepositories.First(x => x.Name == repositoryName), name, version.ToString(), dependencies, string.Empty);
}

protected void given_system_package(string name, string version, params string[] dependencies)
{
AddPackage(Environment.SystemRepository, name, version, dependencies);
AddPackage(Environment.SystemRepository, name, version, dependencies, string.Empty);
}

static void AddPackage(IPackageRepository repository, string name, string version, string[] dependencies)

static void AddPackage(IPackageRepository repository, string name, string version, string[] dependencies, string description)
{
if (repository is InMemoryRepository)
{
Expand All @@ -121,6 +128,7 @@ static void AddPackage(IPackageRepository repository, string name, string versio
Name = name,
Source = repository,
Version = version.ToVersion(),
Description = description,
Dependencies = dependencies.SelectMany(x => DependsParser.ParseDependsInstruction(x).Dependencies).ToList()
});
return;
Expand All @@ -140,7 +148,7 @@ protected void given_currentdirectory_package(string packageName, string version
protected void given_currentdirectory_package(string packageName, Version version, params string[] dependencies)
{
if (Environment.CurrentDirectoryRepository is InMemoryRepository)
AddPackage(Environment.CurrentDirectoryRepository, packageName, version.ToString(), dependencies);
AddPackage(Environment.CurrentDirectoryRepository, packageName, version.ToString(), dependencies,string.Empty);
else
{
var localFile = Environment.CurrentDirectory.GetFile(PackageNameUtility.PackageFileName(packageName, version.ToString())).MustExist();
Expand Down
9 changes: 4 additions & 5 deletions src/OpenWrap.Tests/OpenWrap.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@
<Compile Include="Commands\remove_wrap\removing_by_version_and_last.cs" />
<Compile Include="Commands\remove_wrap\removing_by_version_in_project.cs" />
<Compile Include="Commands\remove_wrap\removing_by_version_in_system.cs" />
<Compile Include="Commands\update_wrap\command_flags\project_and_system_flag_specified.cs" />
<Compile Include="Commands\Wrap\viewWrapCommand.cs" />
<Compile Include="contexts\dependency_manager_context.cs" />
<Compile Include="Commands\update_wrap\command_flags\project_and_system_flag_specified.cs" />
<Compile Include="Commands\update_wrap\project\from_system.cs" />
<Compile Include="Commands\update_wrap\command_flags\defaults.cs" />
<Compile Include="Commands\update_wrap\project_and_system\from_remote.cs" />
Expand All @@ -150,7 +152,6 @@
<Compile Include="Commands\update_wrap\system\from_remote_by_name.cs" />
<Compile Include="Commands\update_wrap\project\not_in_project.cs" />
<Compile Include="Commands\update_wrap\project\from_remote.cs" />
<Compile Include="contexts\dependency_manager_context.cs" />
<Compile Include="contexts\descriptor.cs" />
<Compile Include="contexts\descriptor_readers.cs" />
<Compile Include="contexts\package_graph_visitor.cs" />
Expand Down Expand Up @@ -190,9 +191,7 @@
<HintPath>..\..\..\..\..\..\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\Microsoft.Build.Engine.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Private>false</Private>
<Reference Include="nunit.framework">
<HintPath>..\..\lib\nunit-2.5.5\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
Expand Down
1 change: 1 addition & 0 deletions src/OpenWrap/OpenWrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="PackageManagement\PackageRemoveResultIterator.cs" />
<Compile Include="PackageManagement\PackageUpdateOptions.cs" />
<Compile Include="PackageManagement\PackageUpdateResultIterator.cs" />
<Compile Include="PackageManagement\ViewWrapCommandOutput.cs" />
<Compile Include="PackageModel\InvalidPackageException.cs" />
<Compile Include="PackageModel\IPackageDescriptor.cs" />
<Compile Include="PackageModel\LessThanOrEqualVersionVertex.cs" />
Expand Down
Loading